[root@localhost ~]# curl 192.168.100.120:8080/testb.php
mysql ok![root@localhost ~]# curl 192.168.100.120:8080/testa.php......
9. 启动mysql数据库
[root@localhost mysql]# docker run -it --name mysql --network haha -p 30:3306 --mount type=bind,src=/var/www/haha/,dst=/var/www/haha/ mysql:v1 [root@localhost php]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
797459f3d253 mysql:v1 "/usr/local/mysql/bi…"10 seconds ago Up 8 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp mysql
b3c388b1eed5 php:v1 "/usr/local/php5/sbi…"52 minutes ago Up 52 minutes 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp php
68893f089915 nginx:v1 "/usr/local/nginx/sb…" About an hour ago Up About an hour 0.0.0.0:80->80/tcp, :::80->80/tcp nginx
[root@localhost mysql]# docker inspect mysql #查看mysql容器的ip"Gateway":"192.168.86.1",
"IPAddress":"192.168.86.4",
"IPPrefixLen":24,
"IPv6Gateway":"",
"GlobalIPv6Address":"",
"GlobalIPv6PrefixLen":0,
"MacAddress":"02:42:c0:a8:56:04",
"DriverOpts": null
}[root@localhost ~]# mysql -uroot -h 192.168.86.4 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.18 MySQL Community Server (GPL)
Copyright (c)2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h'for help. Type '\c' to clear the current input statement.
mysql> create database skyucdb;
Query OK, 1 row affected (0.00 sec)
10. 在compose中创建工程,搭建lnmp架构
[root@localhost lnmp]# cat docker-compose.yml
version: "3"
networks:
haha:
external: true
services:
nginx:
container_name: nginx1
image: nginx:v1
ports:
- "8080:80"
volumes:
- /var/lib/docker/volumes/nginx/_data/conf:/usr/local/nginx/conf
- /var/www/haha/:/var/www/haha/
hostname: nginx1
networks:
haha:
ipv4_address: 192.168.86.2
php:
container_name: php1
image: php:v1
ports:
- "9090:9000"
volumes:
- /var/lib/docker/volumes/php/_data/etc/:/usr/local/php5/etc/
- /var/www/haha/:/var/www/haha/
hostname: php1
networks:
haha:
ipv4_address: 192.168.86.3
mysql:
container_name: mysql1
image: mysql:v1
ports:
- "3030:3306"
volumes:
- /var/www/haha/skyuc:/var/www/haha/skyuc
hostname: mysql1
networks:
- haha
[root@localhost lnmp]# docker compose up -d [+] Running 3/3
✔ Container php1 Started 0.0s
✔ Container mysql1 Started 0.0s
✔ Container nginx1 Started 0.0s
[root@localhost lnmp]# docker compose ps -a
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
mysql1 mysql:v1 "/usr/local/mysql/bin/mysqld" mysql 12 seconds ago Up 8 seconds 0.0.0.0:3030->3306/tcp, :::3030->3306/tcp
nginx1 nginx:v1 "/usr/local/nginx/sbin/nginx -g 'daemon off;'" nginx 12 seconds ago Up 8 seconds 0.0.0.0:8080->80/tcp, :::8080->80/tcp
php1 php:v1 "/etc/init.d/php/php-fpm -F" php 12 seconds ago Up 8 seconds 0.0.0.0:9090->9000/tcp, :::9090->9000/tcp