0

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?

1 Answers1

0

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

maes
  • 3
  • 4
  • Hi, I was trying to access through the /logs folder at my /my_app_path where my docker-compose.yaml are located. I define the driver options in the volume and works, thanks ;) – Giovanni Attina do nascimento Apr 01 '20 at 18:59
  • No problem! In your case, the logs: volume entry is just a named volume. It got mounted to a directive managed by docker (somewhere around /var/lib/docker/volumes/logs/_data). You can check the path usually with 'docker volume inspect logs'.Hope this helps for your further projects. might you mark it as answered? – maes Apr 06 '20 at 08:31