卸载旧版本
安装新版本docker-ce前,需要先卸载旧版本docker或docker-engine,和关联依赖。
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
安装Docker CE
使用版本库安装:
设置版本库
1. 安装需要的包。yum-utils, device-mapper-presistent-data, 和lvm2
$ sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
2. 使用下面命令设置一个稳定版本库。
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
由于国内访问不到docker官方镜像,所以改成aliyun的源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3. 可选:开启edge和test版本库。这些版本库也包含在docker-ce.repo中,默认不可用,可以和稳定版本库一起开启:
$ sudo yum-config-manager --enable docker-ce-edge
$ sudo yum-config-manager --enable docker-ce-test
可以通过yum-config-manager命令用—disable和—enable来关闭和开启这些版本库。
$ sudo yum-config-manager --disable docker-ce-edge
通过版本库安装
1. 安装最新版本Docker CE,或者跳到下一步安装指定版本。
$ sudo yum install docker-ce
2. 指定版本Docker CE。
查看可用版本:
$ yum list docker-ce --showduplicates | sort -r
安装选中版本:
$ sudo yum install docker-ce-<VERSION STRING>
3. 运行Docker
$ sudo systemctl start docker
4. 运行hello-world镜像验证docker是否正确安
装
$ sudo docker run hello-world
使用安装包安装:
如果无法使用docker版本库安装(网络有问题,我就遇到了),可以下载.rpm文件手动安装。需要每次更新docker时都要下载一个新的文件。
1. 访问 这里 下载指定docker版本的.rpm文件。
2. 使用下载的安装包安装docker。
$ sudo yum install /path/to/package.rpm
3. 运行docker。
$ sudo systemctl start docker
4. 运行hello-world镜像验证docker是否正确安装
$ sudo docker run hello-world
卸载Docker CE
1. 卸载docker
$ sudo yum remove docker-ce
2. 删除所有镜像,容器,卷,或者自定义配置文件
$ sudo rm -rf /var/lib/docker
以下是实操记录
[scott@scott work]$ sudo yum remove docker \
> docker-client \
> docker-client-latest \
> docker-common \
> docker-latest \
> docker-latest-logrotate \
> docker-logrotate \
> docker-selinux \
> docker-engine-selinux \
> docker-engine
[scott@scott work]$ sudo yum install -y yum-utils \
[scott@scott work]$ sudo yum-config-manager \
> --add-repo \
> https://download.docker.com/linux/centos/docker-ce.repo
[sudo] password for scott:
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
Could not fetch/save url https://download.docker.com/linux/centos/docker-ce.repo to file /etc/yum.repos.d/docker-ce.repo: [Errno 12] Timeout on https://download.docker.com/linux/centos/docker-ce.repo: (28, 'Operation timed out after 30002 milliseconds with 0 out of 0 bytes received')
[scott@scott work]$ sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: 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
[scott@scott work]$ sudo yum install docker-ce
[scott@scott work]$ sudo yum-config-manager --enable docker-ce-edge
Loaded plugins: fastestmirror, langpacks
============================= repo: docker-ce-edge =============================
[docker-ce-edge]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/edge
cache = 0
cachedir = /var/cache/yum/x86_64/7/docker-ce-edge
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = 1
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/docker-ce-edge/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/docker-ce-edge/gpgdir
gpgkey = https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
hdrdir = /var/cache/yum/x86_64/7/docker-ce-edge/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist =
mirrorlist_expire = 86400
name = Docker CE Edge - x86_64
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/docker-ce-edge
pkgdir = /var/cache/yum/x86_64/7/docker-ce-edge/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = docker-ce-edge/x86_64
ui_repoid_vars = releasever,
basearch
username =
[scott@scott work]$ sudo yum-config-manager --enable docker-ce-test
Loaded plugins: fastestmirror, langpacks
============================================================================================== repo: docker-ce-test ===============================================================================================
[docker-ce-test]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/test
cache = 0
cachedir = /var/cache/yum/x86_64/7/docker-ce-test
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = 1
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/docker-ce-test/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/docker-ce-test/gpgdir
gpgkey = https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
hdrdir = /var/cache/yum/x86_64/7/docker-ce-test/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist =
mirrorlist_expire = 86400
name = Docker CE Test - x86_64
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/docker-ce-test
pkgdir = /var/cache/yum/x86_64/7/docker-ce-test/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = docker-ce-test/x86_64
ui_repoid_vars = releasever,
basearch
username =
[scott@scott work]$ sudo yum install docker-ce
[scott@scott work]$ sudo docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
[scott@scott work]$ sudo systemctl start docker
[scott@scott work]$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
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/
[scott@scott work]$