安裝docker
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
這里添加阿里雲的鏡像地址,官方國內下載很慢
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新 yum 緩存
sudo yum makecache fast
安裝 Docker-ce (最新版):
sudo yum -y install docker-ce
安裝指定版本Docker-ce
sudo yum -y install docker-ce-18.06.2.ce
啟動 Docker 后台服務
sudo systemctl start docker
允許開機啟動docker-ce服務
sudo systemctl enable docker.service
測試運行 hello-world
docker run hello-world
[root@k8s-node-1 man1]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f
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@k8s-node-1 man1]#
安裝docker-compose
Docker for Mac
、Docker for Windows
自帶 docker-compose
二進制文件,安裝 Docker 之后可以直接使用。
$ docker-compose --version
docker-compose version 1.17.1, build 6d101fb
二進制安裝
$ sudo curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
創建軟連接
[root@k8s-node-1 man1]# docker-compose --version
-bash: /usr/bin/docker-compose: 沒有那個文件或目錄
[root@k8s-node-1 man1]# ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose
[root@k8s-node-1 man1]# docker-compose --version
docker-compose version 1.17.1, build 6d101fb
PIP 安裝
sudo pip install -U docker-compose
卸載docker
檢查安裝的組件
sudo yum list installed | grep docker
移除相關組件
$ 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-cli
刪除鏡像、容器、卷及自定義的配置文件
rm -rf /var/lib/docker
卸載docker-compose
如果是二進制包方式安裝的,刪除二進制文件即可。
$ sudo rm /usr/local/bin/docker-compose
如果是通過 pip 安裝的,則執行如下命令即可刪除。
$ sudo pip uninstall docker-compose