execute two docker commands
[root@VM_0_7_centos ~]# docker run –name db –env MYSQL_ROOT_PASSWORD=example -d mariadb
[root@VM_0_7_centos ~]# docker run –name MyWordPress –link db:mysql -p 8080:80 -d wordpress
view images
[root@VM_0_7_centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/wordpress latest 9414c91da9a8 9 days ago 408 MB
docker.io/mariadb latest 2c73b3262fff 2 weeks ago 363 MB
docker.io/hello-world latest 2cb0d9787c4d 4 weeks ago 1.85 kB
view port
[root@VM_0_7_centos ~]# netstat -tlnp | grep 8080
tcp6 0 0 :::8080 :::* LISTEN 11164/docker-proxy-
访问url:
http://ip:8080/
user:user
password:password
mail:mail
首先,我们把WordPress项目原有的两个容器停掉
[root@VM_0_7_centos ~]# docker stop db MyWordPress
创建一个项目文件夹~/wordpress,在文件夹下创建一个叫docker-compose.yml的文件,内容如下:
[root@VM_0_7_centos ~]# ls
grafana-5.1.1-1.x86_64.rpm test wordpress zabbix-agent-3.4.8-1.el7.x86_64.rpm zabbix-release-3.4-2.el7.noarch.rpm
[root@VM_0_7_centos ~]# cat wordpress/docker-compose.yml
wordpress:
image: wordpress
links:
- db:mysql
ports:
- 8080:80
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: example
–links(容器互联),-ports(端口映射),-environment(环境变量设置)
创建和启动WordPress服务,生成新的NAMES并且服务UP
[root@VM_0_7_centos ~]# cd wordpress && docker-compose up
[root@VM_0_7_centos ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
eed8e51c7189 wordpress "docker-entrypoint..." 30 minutes ago Up 30 minutes 0.0.0.0:8080->80/tcp wordpress_wordpress_1
f4ad894f2087 mariadb "docker-entrypoint..." 30 minutes ago Up 30 minutes 3306/tcp wordpress_db_1
aca92654af96 sameersbn/gitlab:8.4.4 "/sbin/entrypoint...." About an hour ago Up About an hour 443/tcp, 0.0.0.0:10022->22/tcp, 0.0.0.0:10080->80/tcp gitlab
e92b61cf18c7 sameersbn/redmine:3.2.0-4 "/sbin/entrypoint...." 9 days ago Up About an hour 443/tcp, 0.0.0.0:10083->80/tcp redmine
e038010f4bea sameersbn/postgresql:9.4-12 "/sbin/entrypoint.sh" 9 days ago Up About an hour 5432/tcp postgresql-redmine
511be91cca0a sameersbn/redis:latest "/sbin/entrypoint.sh" 10 days ago Up About an hour 6379/tcp gitlab-redis
e9bba5e833b6 sameersbn/postgresql:9.4-12 "/sbin/entrypoint.sh" 10 days ago Up About an hour 5432/tcp gitlab-postgre-sql
8001906c5274 wordpress "docker-entrypoint..." 10 days ago Exited (0) 33 minutes ago MyWordPress
da706ccdc499 mariadb "docker-entrypoint..." 10 days ago Exited (0) 33 minutes ago db
后续启动方式:
“`
[root@VM_0_7_centos ~]# cd wordpress/
[root@VM_0_7_centos wordpress]# docker-compose start
[root@VM_0_7_centos wordpress]# docker-compose stop