一、环境准备
-
下载docker官方镜像https://download.docker.com/,需下载两个软件包,版本号需对应,如下所示:
docker-ce-17.03.0.ce-1.el7.centos.x86_64.rpm docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch.rpm -
准备操作系统环境,本文以CentOS7.5为例,需要关闭防火墙和selinux,启动iptables
# 关闭防火墙 systemctl stop firewalld systemctl disable firewalld # 关闭selinux vi /etc/selinux/config SELINUX=disabled # 安装并启动iptables yum install iptables-services -y systemctl start iptables systemctl enable iptables
二、安装部署
-
安装软件包
yum install -y docker-ce-* -
设置docker阿里云镜像加速
cp /lib/systemd/system/docker.service /etc/systemd/system/ chmod a+x /etc/systemd/system/docker.service # 编辑docker.service文件 vi /etc/systemd/system/docker.service # 加速地址可在阿里云docker官网申请 ExecStart=/usr/bin/dockerd --registry-mirror=https://kfp63jaj.mirror.aliyuncs.com # 重载服务 systemctl daemon-reload systemctl restart docker # 查看docker进程服务是否正常 ps -ef|grep docker
三、测试使用,以WordPress为例
-
准备docker镜像
docker pull wordpress docker pull mairadb -
运行
docker run --name db --env MYSQL_ROOT_PASSWORD=wz123 -d mariadb docker run --name MyWordPress --link db:mysql -p 8080:80 -d wordpress输入ip:8080即可打开WordPress主页