Axi*_*iol 3 nginx docker docker-compose
我正在尝试通过与卷共享的配置文件来安装 Nginx 容器docker-compose.yml。
这里有docker-compose.yml
version: '3.7'
services:
db:
image: mariadb
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: lamp
phpmyadmin:
image: phpmyadmin/phpmyadmin
depends_on:
- db
restart: always
ports:
- 8080:80
nginx:
image: nginx
depends_on:
- db
ports:
- 8000:80
volumes:
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
# - ./log:/var/log/nginx
# - ./code:/usr/share/nginx/html
php:
image: phpdockerio/php73-fpm
depends_on:
- db
Run Code Online (Sandbox Code Playgroud)
这nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
Run Code Online (Sandbox Code Playgroud)
还有default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/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 /usr/share/nginx/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 html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$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;
#}
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我运行时docker-compose up,我收到这些错误
ERROR: for lamp-compose_nginx_1 Cannot start service nginx: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/host_mnt/e/Projects/lamp-compose/docker/nginx/default.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/15cb114888ab7570fd7da633798ef7f094049965e83d4f4ca5500f7d4a833706/merged\\\" at \\\"/var/lib/docker/overlay2/15cb114888ab7570fd7da633798ef7f09Creating lamp-compose_php_1 ... done
ied host path exists and is the expected type
ERROR: for nginx Cannot start service nginx: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/host_mnt/e/Projects/lamp-compose/docker/nginx/default.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/15cb114888ab7570fd7da633798ef7f094049965e83d4f4ca5500f7d4a833706/merged\\\" at \\\"/var/lib/docker/overlay2/15cb114888ab7570fd7da633798ef7f094049965e83d4f4ca5500f7d4a833706/merged/etc/nginx/conf.d\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
ERROR: Encountered errors while bringing up the project.
Run Code Online (Sandbox Code Playgroud)
我已经看到类似问题的一些答案,说我应该更改- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf为- ./docker/nginx/nginx.conf:/etc/nginx/这对我来说没有意义(而且也不起作用)。
有人知道出了什么问题吗?
从链接的错误来看,路径之一似乎./docker/nginx/nginx.conf, ./docker/nginx/default.conf是目录而不是文件。
我建议您不要将配置文件添加为卷。使用 Nginx 的自定义 docker 映像以及其中的配置。您需要更改 docker-compose 文件并为 Nginx 提供 docker 文件,如下所示
Dockerfile
From nginx:latest
COPY ./docker/nginx/default.conf /etc/nginx/conf.d/default.conf
COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf
Run Code Online (Sandbox Code Playgroud)
撰写
nginx:
build: .
depends_on:
- db
ports:
- 8000:80
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2976 次 |
| 最近记录: |