1.1 查看当前linux内核版本python
uname -r #linux内核要求3.10及以上
1.2 更行yum源linux
sudo yum update
1.3 若是安装过旧版本的话,卸载旧版本docker
sudo yum remove docker docker-common docker-selinux docker-engine
1.4 安装须要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的shell
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
1.5 因为国内网络问题,建议使用国内源,添加yum软件源ubuntu
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #阿里云镜像源
已加载插件:fastestmirror, langpacks adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo
1.6 能够查看全部仓库中全部docker版本,并选择特定版本安装centos
$ yum list docker-ce --showduplicates | sort -r
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
1.7 安装docker安全
$ sudo yum install docker-ce #因为repo中默认只开启stable仓库,故这里安装的是最新稳定版17.12.0 $ sudo yum install <FQPN> # 例如:sudo yum install docker-ce-17.12.1.ce
已安装: docker-ce.x86_64 0:17.12.1.ce-1.el7.centos 做为依赖被安装: audit-libs-python.x86_64 0:2.8.1-3.el7 checkpolicy.x86_64 0:2.5-6.el7 container-selinux.noarch 2:2.66-1.el7 libsemanage-python.x86_64 0:2.5-11.el7 libtool-ltdl.x86_64 0:2.4.2-22.el7_3 policycoreutils-python.x86_64 0:2.5-22.el7 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-2.el7 完毕!
1.8 将docker加入开机启动bash
$ sudo systemctl start docker $ sudo systemctl enable docker
1.9 验证安装是否成功(有client和service两部分表示docker安装启动都成功了)网络
$ sudo docker version
Client: Version: 17.12.1-ce API version: 1.35 Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:15:20 2018 OS/Arch: linux/amd64 Server: Engine: Version: 17.12.1-ce API version: 1.35 (minimum version 1.12) Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:17:54 2018 OS/Arch: linux/amd64 Experimental: false
默认状况下,docker 命令会使用 Unix socket 与 Docker 引擎通信。而只有 root 用户和 docker 组的用户才能够访问 Docker 引擎的 Unix socket。出于安全考虑,通常 Linux 系统上不会直接使用 root 用户。所以,更好地作法是将须要使用 docker 的用户加入 docker 用户组。
2.1 创建docker组app
$ sudo groupadd docker
2.2 将当前用户加入 docker 组:
$ sudo usermod -aG docker $USER
2.3 退出当前终端并从新登陆,进行以下测试。
$ docker version #无需sudo使用管理员权限
Client: Version: 17.12.1-ce API version: 1.35 Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:15:20 2018 OS/Arch: linux/amd64 Server: Engine: Version: 17.12.1-ce API version: 1.35 (minimum version 1.12) Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:17:54 2018 OS/Arch: linux/amd64 Experimental: false
$ docker run hello-world #运行hello world
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 9db2ca6ccae0: Pull complete Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc 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/engine/userguide/
$ docker image ls #列出镜像
仓库名 标签 镜像ID 建立时间 占用空间 REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 2cb0d9787c4d 2 weeks ago 1.85kB