Home  >  Q&A  >  body text

linux - docker creates nginx container, why can't the nginx.conf file be shared?

Execute via command

sudo docker run --name nginx -d -p 80:80 -v $PWD/nginx/conf:/etc/nginx
nginx

The container was created successfully, but could not be started.

You can see it through the log
`
2017/05/24 12:13:34 [emerg] 1#1: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
`

If I share the /etc/nginx/conf.d directory, there is no problem. May I ask why this is happening? Is it a permissions issue?

迷茫迷茫2725 days ago931

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-27 17:46:12

    Wow, buddy, you just killed nginx. Many files of nginx are under /etc/nginx. Don’t mount them like this, just mount a file directly

    $sudo docker run --name nginx -d -p 80:80 -v $PWD/nginx/nginx.conf:/etc/nginx/nginx.conf:ro nginx

    The following is an example of my arrangement using docker-compose

    services:
      nginx:
        build: ./dockerfiles/nginx/
        container_name: nginx-server
        ports:
          - "80:80"
        links:
          - "php-fpm"
          - "webpack-dev-front"
        volumes:
    #网站目录
          - ./app:/var/www/html
          - ./dockerfiles/nginx/conf.d:/etc/nginx/conf.d:ro
          - ./dockerfiles/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
    #日志文件
          - ./logs/nginx:/var/log/nginx

    reply
    0
  • Cancelreply