先启动一台nginx查看ip:
下面开启一台alpine并安装curl测试连通性:
--link
以上测试还可以换一种方式--link
docker-compose
首先创建两个目录:
conf存放nginx的配置文件(图片错了,后面改成conf目录了)
html存放html文件和php文件
<?php
Sdbhost = 'localhost';
Sdbuser = 'root';
$dbpass = '123456':
$conn = mysql_connect (Sdbhost,Sdbuser,Sdbpass);
if(!$conn)
{
die('Could not connet:'.mysgli error());
echo 'mysql connected!!
mysqli close ($conn);
}
?>
然后就是配置文件:
version: "3"
services:
nginx:
image: nginx:alpine
ports:
- 80:80
volumes:
- /root/html:/usr/shara/nginx/html
- /root/conf/nginx.conf:/etc/nginx/nginx.conf
php:
image: devilbox/php-fpm:5.2-work-0.89
volumes:
- /root/html:/var/www/html
mysql:
image: mysql:5.6
environment:
-MYSQL_ROOT_PASSWORD=123456
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /usr/shara/nginx/html;
index index.html index.htm;
}
error_pase 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/shara/nginx/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
}
}
访问流程:
结果就是访问80端口,默认显示index.html。访问phpinfo.php显示信息。访问mysql.php连接成功数据库。