3
votes

I'm working on nginx service using docker-compose, I created the docker-compose.yml file :

    version: '2'
    services:
      nginx:
        image: nginx:1.11.8-alpine
        ports:
          - "8858:80"
        volumes:
          - ./site.conf:/etc/nginx/conf.d/default.conf
          - ./code:/usr/share/nginx/html
          - ./html:/myapp
          - ./site.conf:/etc/nginx/conf.d/site.conf
          - ./error.log:/var/log/nginx/error.log
          - ./nginx.conf:/etc/nginx/nginx.conf:ro

This is the site.conf file

    server {
    listen 80;
    index index.html index.php;
    server_name localhost;
    error_log  /var/log/nginx/error.log;
    location / {
       root /usr/share/nginx/html;
    }

    location /html {
       alias /myapp;
    }
}

This is the result of docker-compose up

ERROR: for ef5152b88a7c_ef5152b88a7c_nginxdocker_nginx_1 Cannot start service nginx: oci runtime error: container_linux.go:247: starting container process caused "process_linux.go:359: container init caused \"rootfs_linux.go:54: mounting \\"/root/nginx-docker/nginx.conf\\" to rootfs \\"/var/lib/docker/aufs/mnt/b463f0e0ca95db8cd570dfb68fcf206df31e86998e725465a7673ca192af8342\\" at \\"/var/lib/docker/aufs/mnt/b463f0e0ca95db8cd570dfb68fcf206df31e86998e725465a7673ca192af8342/etc/nginx/nginx.conf\\" caused \\"not a directory\\"\""

: 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

1
Are you sure nginx.conf exists in the host folder?Stefano
The error pretty clearly reffers to nginx.conf not existing in the folder the compose command was ran fromomu_negru
Thank you @Stefano for your response, after i check for the existance of the nginx.conf , it works fine , but now i'm facing new one nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (21: Is a directory) and [emerg] 1#1: no "events" section in configurationBaini.Marouane

1 Answers

1
votes

This has nothing to do with Nginx.

If you use volumes in docker-compose.yml, always make sure that the files on the left side of the colon : exists! If you miss that, sometimes Docker Compose creates folders instead of files "on the left side" (= on your host) IIRC. Which leads to subsequent errors on the next run.