NGINX logs not being mapped with Docker volumes

dockerdocker-composenginx

I define two log levels in my Nginx config file

http {

    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;
    ...
}

and in the server

server {
  access_log                /var/log/nginx/nginx_access.log;
  error_log                 /var/log/nginx/nginx_error.log;

  location / {
    ...
  }
}

My docker-compose.yaml

services:
  nginx:
    build:
      context: ./nginx
    restart: always
    volumes:
      - logs:/var/log/nginx
    ports:
      - "80:80"
    depends_on:
      - django
...

volumes:
  logs:

But when I run the containers at the logs/ where isn't the access.log, nginx_erro.log, nginx_acess.log or neither a folder/file created by the NGINX but when I check in the NGINX container the files are there.

Is there something I am forgetting?

Best Answer

How are you trying to access the logs on your docker host?

Try to map your named volume onto your host:

services:
  nginx:
    build:
      context: ./nginx
    restart: always
    volumes:
      - logs:/var/log/nginx
    ports:
      - "80:80"
    depends_on:
      - django
...

volumes:
  logs:
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: '/path/on/your/docker/host/to/mount' 

And check if the access & error files are available!

regards,

maesi