skip to Main Content

I have a Flask/Svelte project that uses docker-compose for deployment.

Docker-compose looks like this:

version: "3"
services:
    backend:
        build: ./backend
        container_name: backend
        restart: on-failure
#        env_file: ./backend/.env
        # TODO erase ports. only use for tests
        ports:
            - 5001:5000
    frontend:
        build: ./frontend
        container_name: frontend
        restart: on-failure
        depends_on:
            - backend
    nginx:
        image: nginx:alpine
        container_name: LBA
        restart: on-failure
        volumes:
            - ./nginx/nginx.conf:/etc/nginx
        ports:
            - 80:80
        depends_on:
            - backend
            - frontend

While my frontend/Dockerfile looks like this:

FROM nginx:alpine

EXPOSE 80

COPY ./dist /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/nginx.conf

The project structure looks like this:

Project
|
|___backend
|   |
|   |__...
|
|___frontend
|   |
|   |__...
|   |
|   |__nginx.conf
|
|___docker-compose.yaml

This creates the follo2ing output when run:

...
LBA         | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
LBA         | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
LBA         | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
LBA         | /docker-entrypoint.sh: Configuration complete; ready for start up
LBA         | 2022/10/13 05:17:22 [emerg] 1#1: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
LBA         | nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)

Have I messed something on my docker configurations?

2

Answers


  1. The issue is this bind in your docker-compose.yml:

     volumes:
            - ./nginx/nginx.conf:/etc/nginx
    

    Your are binding your local ./nginx/nginx.conf file to the container’s /etc/nginx which should be a directory but instead becomes nginx.conf named /etc/nginx.

    The solution would be to mount the volume either as ./nginx/nginx.conf:/etc/nginx/nginx.conf or ./nginx:/etc/nginx if you want to override the whole directory.

    Login or Signup to reply.
  2. You can do two separate mappings, i.e.:

    volumes:
      - /opt/nginx/conf.d:/etc/nginx/conf.d
      - /opt/nginx/nginx.conf:/etc/nginx/nginx.conf 
    

    But make sure the local conf.d folder has a working version of NGNIX data files, before you map them.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search