PHP.and.MySQL.Create.Modify.Reuse
PHP&MySQL范例精解_创建、修改、重用-docker环境搭建-5.准备完毕,启动容器,测试gd
Php
docker run -d --rm \
--name virhuiai-php-fpm56 \
--net=virhuiai_nw \
-v /Users/jjkkll/Documents/2020-book-read/7302195625/www/:/var/www \
php-5.6-fpm-gd
若要使用容器外的配置文件,多加个参数:
-v /Users/jjkkll/Documents/2020-book-read/7302195625/docker/php-5.6-fpm-etc/etc/:/usr/local/etc/
Apache
docker run -d --rm \
-p 80:80 \
--name virhuiai-apache \
--net=virhuiai_nw \
-v /Users/jjkkll/Documents/2020-book-read/7302195625/docker/httpd-2.4.37-conf/conf:/usr/local/apache2/conf \
-v /Users/jjkkll/Documents/2020-book-read/7302195625/www/html/:/usr/local/apache2/htdocs \
httpd:2.4.37-alpine
此时查看网络
localhost:html jjkkll$ docker network inspect virhuiai_nw
[
{
"Name": "virhuiai_nw",
....
"Containers": { "0234a685bbc34cfd8f49bbce5a04d4f71b4d72f88b46f1e39718f35fa746b582": {
"Name": "virhuiai-mysql57",
"EndpointID": "4a083a526219c3aca43161f614c7d96088b1175d6e187355e564bd854ba8bfe3",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
},
"52b86a5585c80f26a49d38c9ca955d80fcb4a9badc26f877bb1b975ea487c52d": {
"Name": "virhuiai-apache",
"EndpointID": "6340b0d51aee501cf18879e02c333e8924a673d16191b0e5bc3cacb74d47483c",
"MacAddress": "02:42:ac:12:00:04",
"IPv4Address": "172.18.0.4/16",
"IPv6Address": ""
},
"7d5c3f273e9cbcdb4c1332a06e085b1f3d3f0a43ee16f864967cd267c1cf98cc": {
"Name": "virhuiai-php-fpm56",
"EndpointID": "411e66b42037f85584719af278620b62e54ac00578960817ce0d7e0065560733",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
进入apache容器,可以ping到php的
localhost:~ jjkkll$ bash -c "clear && docker exec -it virhuiai-apache sh"
# 容器内
ping virhuiai-php-fpm56
PING virhuiai-php-fpm56 (172.18.0.3): 56 data bytes
64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.180 ms
64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.102 ms
64 bytes from 172.18.0.3: seq=2 ttl=64 time=0.099 ms
^C
--- virhuiai-php-fpm56 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.099/0.127/0.180 ms
Mysql
docker run -p 3306:3306 \
--volumes-from virhuiai-mysql57-container \
--name virhuiai-mysql57 \
-e MYSQL_ROOT_PASSWORD=wb6Y7CTgA \
-d \
mysql:5.7
测试gd
使用书中的img/captcha.php,放到/var/www/html相应位置
成功出现图片