Search code examples
dockerubuntunginxnginx-config

Can't volume map nginx.conf to directory in container


First of all, I am only experiencing this issue on my Linux VPS. This issue doesn't exist on my Windows development machine.

My VPS is running Ubuntu 23.04

The issue

When I attempt to launch my docker container from a docker-compose script, the Nginx continer errors and spits out this:

root@srv502529:/docker_projects/personal-site-2024# docker-compose up
Creating network "personal-site-2024_default" with the default driver
Creating personal-site-2024_api_proxy_server_1 ... done
Creating personal-site-2024_webserver_1        ... done
Creating personal-site-2024_cms_server_1       ... done
Creating personal-site-2024_nginx_1            ... error

ERROR: for personal-site-2024_nginx_1  Cannot start service nginx: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/nginx.conf" to rootfs at "/etc/nginx/nginx.conf": mount /nginx.conf:/etc/nginx/nginx.conf (via /proc/self/fd/6), flags: 0x5000: 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: for nginx  Cannot start service nginx: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/nginx.conf" to rootfs at "/etc/nginx/nginx.conf": mount /nginx.conf:/etc/nginx/nginx.conf (via /proc/self/fd/6), flags: 0x5000: 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

I think the common cause of this is that nginx.conf isn't where it's specified, but in my case it absolutely is: screenshot of my project directory via SSH screenshot of my project directory VIA SFTP

Snippet of docker-compose

services:
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - /nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - webserver
      - api_proxy_server
      - cms_server

What I've tried

I've tried using this volume mapping ./nginx:/etc/. It apparently loads and I get a done message in the console, but then I get this error:

nginx_1             | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx_1             | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx_1             | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx_1             | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
nginx_1             | /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
nginx_1             | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx_1             | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
nginx_1             | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx_1             | 2024/04/08 15:35:46 [emerg] 1#1: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
nginx_1             | nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)

Solution

  • You provide /nginx.conf as the path to the file to mount, but your structure suggests it should either be ./nginx.conf or /docker_projects/personal-site-2024/nginx.conf if absolute paths are preferred.