先搞定docker-compose,使它能够使用:
[[email protected] ~]# curl -L https://github.com/docker/compose/releases/download/1.25.1-rc1/docker-compose-`uname -s-
uname -m` -o /usr/local/bin/docker-compose
[[email protected] ~]# chmod +x /usr/local/bin/docker-compose
[[email protected] ~]# docker-compose -v
docker-compose version 1.25.1-rc1, build d92e9bee
需要两个包,我的是下面的本地包,你们也可再网上下载,不过要注意版本号:
将他们做成镜像:
[[email protected] ~]# docker load < mysql-5.7.tar
[[email protected] ~]# docker load < wordpress.tar
得出以下两个镜像:
创建一个目录,再目录里面写入docker-compose.yml文件:
[[email protected] ~]# mkdir wordpress
[[email protected] ~]# cd wordpress/
[[email protected] wordpress]# vim docker-compose.yml
version: "3.1"
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: 123.com
WORDPRESS_DB_NAME: wordpress
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: 123.com
MYSQL_ROOT_PASSWORD: 123.com启动容器: [[email protected] wordpress]# docker-compose up -d 最后浏览器访问:ip地址加端口8080:
浏览器访问不了是因为没有开启路由转发。开启就好,以下命令:
[[email protected] wordpress]# echo net.ipv4.ip_forward = 1 >> /etc/sysctl.conf
[[email protected] wordpress]# systemctl restart network
就可以访问了
原文地址:https://blog.51cto.com/13997536/2460992