如何搭建一个含有 docker 的零碎开发环境,有如下三种办法:
装置
1. 手动装置
应用 vagrant 启动零碎后,手动装置
https://docs.docker.com/install/linux/docker-ce/centos/
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
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 如果想装置特定版本,则应用
# sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
sudo yum install -y docker-ce
sudo systemctl start docker
2. vagrant 主动装置
在 vagrant 创立零碎后主动搭建 docker 环境,config.vm.provision "shell"
可能在虚拟机被创立的时候主动执行
config.vm.provision "shell", inline: <<-SHELL
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
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce
sudo systemctl start docker
SHELL
3. docker-machine 主动装置
详见下节
4. 脚本主动装置
curl -fsSL https://get.docker.com -o get-docker.sh
卸载
sudo yum remove docker-ce
sudo rm -rf /var/lib/docker
查看版本
docker version
Client:
Version: 18.03.1-ce
API version: 1.37
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:20:16 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.03.1-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:23:58 2018
OS/Arch: linux/amd64
Experimental: false
常见问题
- 首次装置,启动失败,定位问题所在
# 通过 systemctl 来排查
systemctl status docker
# 间接运行 systemctl 的 execStart 来排查
/usr/bin/dockerd