创建docker-compose 目录
工作目录(一会儿docker-compose命令将在工作目录下执行)
1 2 3
| mkdir -p /docker/web/www mkdir -p /docker/web/nginx/log mkdir -p /docker/web/nginx/conf.d
|
添加nginx配置:
1
| vim /docker/web/nginx/conf.d/detault.conf
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| server { listen 80 default_server; listen [::]:80; server_name localhost; location / { root /home/www; index index.html index.htm index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
|
添加网页内容:
1 2 3
| mkdir /home/docker-nginx/www #创建目录 echo '<script>alert('installation complete')</script>' > index.html #创建index.html文件并写入内容 echo '<?php phpinfo();?>' > index.php #创建index.php文件并写入内容
|
1
| vim /docker/web/www/index.php
|
Docker-compose:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| version: "3" services: nginx: image: nginx:latest container_name: "nginx" restart: always ports: - "80:80" - "443:443" environment: - TZ=Asia/Shanghai depends_on: - "php" volumes: - " /docker/web/nginx/conf.d:/etc/nginx/conf.d" - " /docker/web/www:/home/www" - " /docker/web/nginx/log:/var/log/nginx" networks: - net-app php: image: php:7.4-fpm container_name: "php" restart: always ports: - "9000:9000" environment: - TZ=Asia/Shanghai volumes: - " /docker/web/www:/home/www" networks: - net-app
networks: net-app:
|
重启容器
1
| docker-compose up -d --force-recreate
|