1、检查系统版本

# 1、Linux的内核要大于3.0才可以使用docker
~# uname -r
4.15.0-29-generic

# 2、查看当前操作系统的版本
~# cat /etc/os-release 
NAME="Ubuntu"
VERSION="16.04.5 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.5 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

2、Ubuntu换源

  • 以下换源操作针对在执行apt-get update过程中一直提示忽略等信息,不能完成更新的可以尝试,如果可以正常使用apt-get update这一步可以省略。在这里插入图片描述

  • 打开配置文件sudo gedit /etc/apt/sources.list

  • 删除图中这段内容,然后替换成阿里源。删除之前建议先备份一下。在这里插入图片描述

  • 替换成如下的内容

  •   # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
      deb https://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
      deb https://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
      deb https://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
      deb https://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
      # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
      
    
  • 保存后执行apt-get update

3、安装docker

3.1、卸载旧的docker版本

如果之前要安装过docker,需要先卸载,没有安装过的话跳过这一步。

apt-get remove docker docker-engine docker.io containerd runc

3.2、允许apt命令可以使用HTTPS访问Docker repository

apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

安装完成如下图所示:

在这里插入图片描述

3.3、添加Docker官方的GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

安装完成如下图所示:
在这里插入图片描述

验证key(搜索后8位即可显示完成秘钥):

apt-key fingerprint 0EBFCD88

在这里插入图片描述

3.4、设置repository版本为stable并更新软件列表

add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update

3.5、开始安装docker

apt-get install docker-ce docker-ce-cli containerd.io

在这里插入图片描述

3.6、查看docker版本

安装完成后,在命令行输入docker --version;出现docker版本信息即表示安装成功。
在这里插入图片描述

4、docker换源

docker服务器在国外,在平常使用docker下载镜像的过程中,难免会导致下载很慢的情况,可以将docker换成阿里源,这样下载就快很多了。

登录阿里云,在左侧菜单栏的镜像工具中找到镜像加速器,然后选择Ubuntu操作系统
在这里插入图片描述

按照官方的操作方法,在命令行输入意向命令

sudo mkdir -p /etc/docker

sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://0orggnrc.mirror.aliyuncs.com"]
}
EOF

sudo systemctl daemon-reload
sudo systemctl restart docker

这样就完成了加速器的配置

5、运行docker

5.1、hellow-world镜像,

输入:docker run hello-world,输出以下内容表示成功:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

5.2、http镜像

输入docker run -d -p 80:80 httpd,提示以下内容表示镜像安装完成
在这里插入图片描述

在浏览器中访问ip:80,出现下图所示的内容即表示docker成功安装。
在这里插入图片描述

6、查看docker镜像

刚刚我们下载了hello-worldhttpd两个镜像,在命令行输入docker images,即可查看下载的镜像信息。

在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐