From 78b06025c9f66ff4b77d13e581aeb1070c340016 Mon Sep 17 00:00:00 2001 From: kkmike999 Date: Wed, 21 Feb 2018 18:06:05 +0800 Subject: [PATCH] no message --- conf.d/nginx.conf | 18 +++++++++++++++ docker-compose.yml | 50 ++++++++++++++++++++++++++++++++++++++++++ html/connect_mysql.php | 19 ++++++++++++++++ html/index.php | 3 +++ php-mysqli/Dockerfile | 5 +++++ 5 files changed, 95 insertions(+) create mode 100644 conf.d/nginx.conf create mode 100644 docker-compose.yml create mode 100644 html/connect_mysql.php create mode 100644 html/index.php create mode 100644 php-mysqli/Dockerfile diff --git a/conf.d/nginx.conf b/conf.d/nginx.conf new file mode 100644 index 0000000..8731d5b --- /dev/null +++ b/conf.d/nginx.conf @@ -0,0 +1,18 @@ +server { + listen 80; + server_name localhost; + location / { + root /var/www/html; + index index.html index.htm index.php; + } + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /var/www/html; + } + location ~ \.php$ { + fastcgi_pass php:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; + include fastcgi_params; + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b4e69da --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,50 @@ +version: '3' +services: + nginx: + image: nginx:latest + # 端口映射 + ports: + - "80:80" + # 依赖关系 先跑php + depends_on: + - "php" + # 数据卷 + volumes: + # 映射主机./conf.d目录到容器/etc/nginx/conf.d目录 + - "$PWD/conf.d:/etc/nginx/conf.d" + - "$PWD/html:/usr/share/nginx/html" + networks: + - app_net + # 容器名称 + container_name: "compose-nginx" + php: + build: ./php-mysqli + image: php:7.2-fpm-mysqli + ports: + - "9000:9000" + volumes: + - "$PWD/html:/var/www/html" + networks: + - app_net + container_name: "compose-php" + mysql: + image: mysql:5.7 + ports: + - "3306:3306" + # 环境变量 + environment: + # mysql密码 + - MYSQL_ROOT_PASSWORD=123456 + networks: + app_net: + # 固定子网ip,网段必须在子网络10.10.*.* + ipv4_address: 10.10.10.1 + container_name: "compose-mysql" +networks: + # 配置docker network + app_net: + driver: bridge + ipam: + config: + # 子网络 + - subnet: 10.10.0.0/16 diff --git a/html/connect_mysql.php b/html/connect_mysql.php new file mode 100644 index 0000000..1ab78e5 --- /dev/null +++ b/html/connect_mysql.php @@ -0,0 +1,19 @@ +"; + + echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; + echo "
"; + + echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; + exit; +} + +echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL. "\n"; +echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL. "\n"; + +mysqli_close($link); +?> \ No newline at end of file diff --git a/html/index.php b/html/index.php new file mode 100644 index 0000000..f35a8ef --- /dev/null +++ b/html/index.php @@ -0,0 +1,3 @@ +