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

时间:2016-01-18 16:50:46

标签: nginx docker lxc

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

1 个答案:

答案 0 :(得分:0)

您的server区块应位于server { location / { root /home/username/Documents/My Folder/Repos/my-app; try_files $uri index.html; } } 区块内:

bool f()

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