操作系统:Red Hat Enterprise Linux Server release 7.0 (Maipo)
1) docker 环境搭建
配置 redhat option repo
yum install docker
docker-1.3.2-4.el7.x86_6
2) pull docker images mysql 和wordpress
docker pull wordpress
docker pull mysql
3) 运行 docker container
docker run –name some-mysql -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql
4)连接mysql container,测试container可用
docker run -it –link some-mysql:mysql –rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
5)运行 ,并link mysql
docker run –name some-wordpress –link some-mysql:mysql -d wordpress
6) 当前docker process 状态如下:
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f82070c7d7dc wordpress:4 "/entrypoint.sh apac 2 days ago Up 2 days 80/tcp some-wordpress
2990a0a68aff mysql:latest "/entrypoint.sh mysq 2 days ago Up 2 days 3306/tcp some-mysq
7) stop container
#docker stop some-wordpress
some-wordpress
[root@osev3 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2990a0a68aff mysql:latest "/entrypoint.sh mysq 2 days ago Up 2 days 3306/tcp some-mysql
8) start conainter
#docker start some-wordpress
some-wordpress
#docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f82070c7d7dc wordpress:4 "/entrypoint.sh apac 2 days ago Up 21 seconds 80/tcp some-wordpress
2990a0a68aff mysql:latest "/entrypoint.sh mysq 2 days ago Up 2 days 3306/tcp some-mysql
7) 获取当前 wordpress container 的IP
# docker inspect f82070c7d7dc |grep IP
"IPAddress": "172.17.0.7",
"IPPrefixLen": 16,
8)在wordpress 内部访问 wordpess
#docker exec f82070c7d7dc curl -s http://172.17.0.7/
#docker exec f82070c7d7dc ps
PID TTY TIME CMD
1 ? 00:00:10 apache2
142 ? 00:00:00 ps
9)wordpress 不能被访问,出什么错了? 估计是没有export 端口,那我们重新run container,并 export 端口
#docker stop some-wordpress
#docker rm some-wordpress
some-wordpress
# docker run –name some-wordpress –link some-mysql:mysql -p 80:80 -d wordpress
8212cc3920a9e42134b73e9af3ffaf7926f7b400ec428aa102474ade5dce51f1
10) 访问,curl http://127.0.0.1 没有响应。 猜测是防火墙问题。
原文链接:https://blog.csdn.net/yamaxitas/article/details/42173907