Docker 分为 CE 和 EE 两大版本。CE 即社区版(免费,支持周期 7 个月),EE 即企业版,强调安全,付费使用,支持周期 24 个月。
Docker CE 分为 stable, test, 和 nightly 三个更新频道。每六个月发布一个 stable 版本 (18.09, 19.03, 19.09...)。
根据官方文档安装docker-ce
先卸载系统自带的docker组件
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
然后安装所需的包。yum-utils提供了yum-config-manager 效用,并device-mapper-persistent-data和lvm2由需要 devicemapper存储驱动程序。
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
使用以下命令设置稳定存储库
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
安装DOCKER CE,加入开机自启动
yum install docker-ce -y
systemctl start docker
systemctl enable docker
官方镜像网址https://hub.docker.com/explore/
更换国内镜像源
[root@localhost docker]# vim /etc/docker/daemon.json
{
"registry-mirrors": [ "https://registry.docker-cn.com" ]
}
备注:配置文件/etc/docker/daemon.json
如果错误会导致docker进程无法启动,如果在配置文件中多加个双引号会发生如下报错
[root@cobbler ~]# systemctl restart docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
[root@cobbler ~]# journalctl -xe
-- Unit docker.socket has begun starting up.
Apr 19 16:59:33 cobbler systemd[1]: Listening on Docker Socket for the API.
-- Subject: Unit docker.socket has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.socket has finished starting up.
--
-- The start-up result is done.
Apr 19 16:59:33 cobbler systemd[1]: start request repeated too quickly for docker.service
Apr 19 16:59:33 cobbler systemd[1]: Failed to start Docker Application Container Engine.
-- Subject: Unit docker.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.service has failed.
--
-- The result is failed.
Apr 19 16:59:33 cobbler systemd[1]: Unit docker.service entered failed state.
Apr 19 16:59:33 cobbler systemd[1]: docker.service failed.
拉取测试镜像运行
[root@localhost ~]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for hello-world:latest
[root@localhost ~]# docker run hello-world
WARNING: IPv4 forwarding is disabled. Networking will not work.
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/
备注:因为docker的容器运行时需要将端口映射到主机的端口上,因此不能使用centos7自带的防火墙firewalld,需要安装iptables组件(6版本之前的防火墙)
#关闭新防火墙模块firewalld
systemctl disabled firewalld
#安装iptables以方便使用Docker的端口映射
yum install -y iptables-services
systemctl enable iptables
systemctl start iptables