一.安裝docker
1.安裝需要的軟件包, yum-util 提供yum-config-manager功能,另外兩個是devicemapper驅動依賴的
yum install -y yum-utils device-mapper-persistent-data lvm2
[root@izm5e2q95pbpe1hh0kkwoiz ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已加載插件:fastestmirror
base | 3.6 kB 00:00:00
bintray-rabbitmq-server | 1.3 kB 00:00:00
epel | 4.7 kB 00:00:00
extras
......
2.設置yum源
- yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo(中央倉庫)
- yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo(阿里倉庫)
[root@izm5e2q95pbpe1hh0kkwoiz ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加載插件:fastestmirror
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
3.可以查看所有倉庫中所有docker版本,並選擇特定版本安裝
yum list docker-ce --showduplicates | sort -r
[root@izm5e2q95pbpe1hh0kkwoiz ~]# yum list docker-ce --showduplicates | sort -r
已加載插件:fastestmirror
可安裝的軟件包
Loading mirror speeds from cached hostfile
docker-ce.x86_64 3:19.03.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.12-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.11-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.10-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
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.3.ce-1.el7 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
4.安裝Docker,命令:yum install docker-ce-版本號
安裝之前首先刪除舊的docker,否則會報錯
yum remove docker docker-common docker-selinux docker-engine
如果不刪除,有可能會報錯
Transaction check error: file /usr/bin/docker from install of docker-ce-cli-1:19.03.9-3.el7.x86_64 conflicts with file from package docker-common-2:1.13.1-204.git0be3e21.el7.x86_64 file /usr/bin/dockerd from install of docker-ce-3:19.03.9-3.el7.x86_64 conflicts with file from package docker-common-2:1.13.1-204.git0be3e21.el7.x86_64
安裝docker
# 安裝指定版本的docker yum install docker-ce-19.03.9 # 安裝最新版本的docker yum install docker-ce
root@izm5e2q95pbpe1hh0kkwoiz ~]# yum install docker-ce-19.03.9
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 docker-ce.x86_64.3.19.03.9-3.el7 將被 安裝
--> 正在處理依賴關系 container-selinux >= 2:2.74,它被軟件包 3:docker-ce-19.03.9-3.el7.x86_64 需要
--> 正在處理依賴關系 containerd.io >= 1.2.2-3,它被軟件包 3:docker-ce-19.03.9-3.el7.x86_64 需要
--> 正在處理依賴關系 docker-ce-cli,它被軟件包 3:docker-ce-19.03.9-3.el7.x86_64 需要
--> 正在處理依賴關系 libcgroup,它被軟件包 3:docker-ce-19.03.9-3.el7.x86_64 需要
......
作為依賴被升級:
audit.x86_64 0:2.8.5-4.el7 audit-libs.x86_64 0:2.8.5-4.el7
libselinux.x86_64 0:2.5-15.el7 libselinux-devel.x86_64 0:2.5-15.el7
libselinux-python.x86_64 0:2.5-15.el7 libselinux-utils.x86_64 0:2.5-15.el7
libsemanage.x86_64 0:2.5-14.el7 libsepol.x86_64 0:2.5-10.el7
libsepol-devel.x86_64 0:2.5-10.el7 policycoreutils.x86_64 0:2.5-34.el7
selinux-policy.noarch 0:3.13.1-266.el7 selinux-policy-targeted.noarch 0:3.13.1-266.el7
完畢!
5.沒啟動docker之前查看docker版本
[root@izm5e2q95pbpe1hh0kkwoiz ~]# docker -v
Docker version 19.03.12, build 48a66213fe
[root@izm5e2q95pbpe1hh0kkwoiz ~]# docker version
Client: Docker Engine - Community
Version: 19.03.12
API version: 1.40
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:46:54 2020
OS/Arch: linux/amd64
Experimental: false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
6.啟動docker之后查看docker版本
啟動docker
# 啟動docker
systemctl start docker
# 允許開機啟動
systemctl enable docker
驗證安裝是否成功(有client和service兩部分表示docker安裝啟動都成功了)
[root@izm5e2q95pbpe1hh0kkwoiz ~]# docker -v
Docker version 19.03.12, build 48a66213fe
root@izm5e2q95pbpe1hh0kkwoiz ~]# docker version
Client: Docker Engine - Community
Version: 19.03.12
API version: 1.40
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:46:54 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.9
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 9d988398e7
Built: Fri May 15 00:24:05 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
7.通過運行 hello-world 映像來驗證是否正確安裝了 Docker
docker run hello-world
成功運行
[root@VM-12-13-centos home]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519
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/
[root@VM-12-13-centos home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@VM-12-13-centos home]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
603540d2e264 hello-world "/hello" 11 seconds ago Exited (0) 10 seconds ago zealous_sanderson
8.卸載 docker
刪除安裝包:
yum remove docker-ce
刪除鏡像、容器、配置文件等內容:
rm -rf /var/lib/docker
二.安裝docker-compose
1.方法一.官網方法(docker.com)
注意事項
- mac和windows客戶端下安裝完docker之后,docker-compose是帶着的
- linux系統下,需要先安裝docker,然后再安裝docker-compose
- 以非root用戶運行docker-compose
①下載最新穩定版本
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-\((uname -s)-\)(uname -m)" -o /usr/local/bin/docker-compose
②賦予文件執行權限
sudo chmod +x /usr/local/bin/docker-compose
③建立一個軟鏈到/usr/bin/目錄下
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
④查看版本
docker-compose --version
2.通過pip進行安裝
①安裝pip
yum -y install epel-release
yum -y install python-pip
②查看版本
pip --version 或 pip -V
③更新pip
pip install --upgrade pip
④安裝docker-compose
pip install docker-compose
⑤查看docker compose的版本
docker-compose version
⑥如果安裝出錯
Cannot uninstall ‘requests’. It is adistutils installed project and thus we cannot accurately determine which filesbelong to it which would lead to only a partial uninstall.
解決方法
pip install docker-compose--ignore-installed requests
沒有任何錯誤,會出現安裝成功界面
3.離線安裝
①訪問https://github.com/docker/compose/releases,獲取docker-compose-Linux-x86_64下載鏈接
https://github.com/docker/compose/releases/download/1.26.0/docker-compose-Linux-x86_64
②下載docker-compose-Linux-x86_64到/usr/local/bin/
[root@izm5e2q95pbpe1hh0kkwoiz bin]# wget https://github.com/docker/compose/releases/download/1.26.0/docker-compose-Linux-x86_64
--2020-06-29 10:41:41-- https://github.com/docker/compose/releases/download/1.26.0/docker-compose-Linux-x86_64
正在解析主機 github.com (github.com)... 13.229.188.59
正在連接 github.com (github.com)|13.229.188.59|:443... 已連接。
......
③重命名docker-compose-Linux-x86_64為docker-compose
[root@izm5e2q95pbpe1hh0kkwoiz bin]# mv docker-compose-Linux-x86_64 docker-compose
④添加可執行權限和查看docker compose版本
# 添加可執行權限
sudo chmod +x /usr/local/bin/docker-compose
# 查看docker-compose版本
docker-compose -v
站在巨人肩膀上摘蘋果
https://blog.csdn.net/ytangdigl/article/details/103831739