安装compuse
[root@localhost ~]# curl -L "https://get.daocloud.io/docker/compose/releases/download/1.27.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
授权
[root@localhost ~]# chmod 755 !$
chmod 755 /usr/local/bin/docker-compose
查看版本信息
查看docker的版本
[root@localhost ~]# docker --version
Docker version 18.09.6, build 481bc77156
这才是查看docker-compose的版本
[root@localhost ~]# docker-compose --version
docker-compose version 1.27.3, build 4092ae5d
部署wordpress
编辑配置文件
[root@localhost ~]# cat docker-compose.yml
version: '2'
services:
xd_db:
image: mariadb:latest
restart: always
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: wp_password
xd_wp:
image: wordpress:latest
restart: always
depends_on:
- xd_db
ports:
- "8888:80"
environment:
WORDPRESS_DB_HOST: xd_db:3306
WORDPRESS_DB_PASSWORD: wp_password
volumes:
db_data:
配置镜像仓库
[root@localhost ~]# cat /etc/docker/daemon.json
{
"registry-mirrors":["https://dhp9bx4f.mirror.aliyuncs.com","http://hub.c.163.com"],"insecure-registries":["192.168.200.69:5000"]
}
重启docker
systemctl restrat docker
启动容器
[root@localhost ~]# docker-compose up -d
成功后
查看服务什么状态,可以看到两个端口,表示成功
[root@localhost ~]# docker-compose ps -a
Name Command State Ports
---------------------------------------------------
root_xd_db_1 docker- Up 3306/tcp
entrypoint.sh
mysqld
root_xd_wp_1 docker- Up 0.0.0.0:8888
entrypoint.sh ->80/tcp
apach ...
用浏览器访问192.168.200.69:8888
列出所有镜像
[root@localhost ~]# docker-compose images
Container Reposito Tag Image Id Size
ry
---------------------------------------------------
root_xd_d mariadb latest 3a348a04 406.5 MB
b_1 a815
root_xd_w wordpres latest bc5f6567 549.8 MB
p_1 s b763
停止和启动服务
[root@localhost ~]# docker-compose stop
Stopping root_xd_wp_1 ... done
Stopping root_xd_db_1 ... done
[root@localhost ~]# docker-compose start
Starting xd_db ... done
Starting xd_wp ... done
down掉服务
[root@localhost ~]# docker-compose down
Stopping root_xd_wp_1 ... done
Stopping root_xd_db_1 ... done
Removing root_xd_wp_1 ... done
Removing root_xd_db_1 ... done
Removing network root_default
不仅会停止,而且会移除
开启服务
[root@localhost ~]# docker-compose up
删除所有容器
docker-compose rm -s