在Centos7上部署Docker
先判断您的Centos
内核版本是否大于 3.10
(因为会存在兼容性问题)
uname -r
输入以下命令来安装docker
:
1. yum install -y #更新该Liunx系统的内核版本。
2. yum -y install docker #安装docker
3. systemctl start docker #启动doker服务
如果启动服务时出现了以下信息:
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
可以进行以下操作:
vi /etc/sysconfig/docker-storage
修改配置文件为:
DOCKER_STORAGE_OPTIONS="--selinux-enabled --log-driver=journald --signature-verification=false"
接着配置以下参数
vi /etc/docker/daemon.json
{
"storage-driver": "devicemapper",
"registry-mirrors": ["https://aj2rgad5.mirror.aliyuncs.com"] //设置镜象
}
1. systemctl daemon-reload #重载daemon文件
2. systemctl restart docker #重启docker服务
运行完以上命令后,若没有报错,则表示配置成功。
开放管理端口映射
1. vi /lib/systemd/system/docker.service
2. 找到 ExecStart=/usr/bin/dockerd-current 并改为:
ExecStart=/usr/bin/dockerd-current -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock -H tcp://0.0.0.0:7654
其中 2375 为管理端口,7654 为备用端口
3. vi ~/.bashrc #写入 2375 管理端口号
尾部添加: export DOCKER_HOST=tcp://0.0.0.0:2375
4. source ~/.bashrc #重载 .bashrc 文件
重启docker
服务
systemctl restart docker.service
测试是否安装成功并正确运行
docker run hello-world
运行二次,如果出现了以下信息:
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/
则表示一切都 ok
了。
本文参考: