为什么我的容器不会 运行?

Why won't my container run?

Ubuntu 15.10

将此 运行 命令与官方 nginx 图像一起使用:

sudo docker run -dit --name="myApp" -p 8181:80 -v /home/username/Documents/My\ Folder/Repos/my-app:/usr/share/nginx/html:ro -v /home/username/Documents/My\ Folder/Repos/my-app/nginx.conf:/etc/nginx/nginx.conf:ro nginx

如果没有第二个 VOLUME 声明(没有自定义 nginx.conf),运行 没问题,但我最近添加了它,因为我需要配置一些东西(AngularJS html5 路由模式).

我的nginx.conf(我只是添加了location设置,其他的都是从原来的复制过来的):

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

location / {
    root /home/username/Documents/My Folder/Repos/my-app;
    try_files $uri index.html;
}

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    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;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

您的 location 块应该在 server 块内:

server {
  location / {
    root /home/username/Documents/My Folder/Repos/my-app;
    try_files $uri index.html;
  }
}

有关更多信息的教程:https://www.digitalocean.com/community/tutorials/understanding-the-nginx-configuration-file-structure-and-configuration-contexts#the-location-context