CentOS 7安裝Docker官方指南
阿新 • • 發佈:2018-12-05
解除安裝舊版本
安裝新版本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
以下是實操記錄
[[email protected] 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
[[email protected] work]$ sudo yum install -y yum-utils \
[[email protected] 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')
[[email protected] 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
[[email protected] work]$ sudo yum install docker-ce
[[email protected] 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 =
[[email protected] 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 =
[sc[email protected] work]$ sudo yum install docker-ce
[[email protected] 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'.
[[email protected] work]$ sudo systemctl start docker
[[email protected] 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/
[[email protected] work]$