您的位置:首页 > 运维架构 > Docker

docker-compose.yml编排LNMP,php找不到文件,注意nginx配置文件

2018-09-10 16:45 986 查看
version: "3"
services:
mysql:
container_name: dev-mysql
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
environment: #变量
MYSQL_ROOT_PASSWORD: 123456
ports:
- "3306:3306"
expose:
- "3306"
restart: always
volumes:
- /var/mysql/3306:/var/lib/mysql:rw
- /etc/mysql/3306:/etc/mysql/conf.d:ro
deploy:
replicas: 1 # 运行数量
networks:
- lnmp
redis:
container_name: dev-redis
image: redis:latest
#    ports:
#      - "6379:6379"
expose:
- "6379"
volumes:
- "/var/redis/6379:/data:rw"
- "/etc/redis/6379.conf:/usr/local/etc/redis/redis.conf"
deploy:
replicas: 1
restart: always #重启
networks:
- lnmp
php:
container_name: dev-php-fpm
build:
context: ./
dockerfile: Dockerfile
image: dev-php-fpm:7.2.9 #给镜像起名加标签
#    ports:
#      - "9000:9000"
expose:
- "9000"
links:
- mysql
restart: always
networks:
- lnmp
volumes:
- /var/html:/var/www/html
nginx:
container_name: dev-nginx
image: nginx:latest
volumes:
- /var/html:/usr/share/nginx/html:rw
- /etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- "80:80"
- "443:443"
restart: always
links:
- php
deploy:
replicas: 1
depends_on:
- mysql
- redis
- php
networks:
- lnmp
networks:
lnmp:
driver: bridge

php-7.2.9-fpm的Dockerfile

FROM php:7.2.9-fpm
RUN apt-get update && apt-get install imagemagick libmagickwand-dev -y \
&& pecl install redis-4.1.1 \
&& pecl install imagick-3.4.3 \
&& pecl install PDO_MYSQL-1.0.2 \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-enable redis imagick

nginx的配置,(注意php部分的root和fastcgi_pass,)

#user  nobody;
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
worker_connections  1024;
}

http {
include       mime.types;
default_type  application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
listen       80;
server_name  localhost;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
root   /usr/share/nginx/html;
index  index.html index.htm;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1; #}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root           /var/www/html;
fastcgi_pass   php:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
include        fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_name  localhost;

#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers  on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息