docker中的nginx不起作用

时间:2018-01-21 20:48:29

标签: docker nginx

我有以下Dockerfile

FROM ubuntu:latest

USER root

RUN apt-get update
RUN apt-get install -y nginx nodejs

RUN rm -v /etc/nginx/nginx.conf

# Copy a configuration file from the current directory
ADD nginx.conf /etc/nginx/

ADD Front-Dev/v2/desktop /usr/share/nginx/html/
ADD Front-Dev/v2/desktop /var/www/html/

# Append "daemon off;" to the beginning of the configuration
RUN echo "daemon off;" >> /etc/nginx/nginx.conf

# Expose ports
EXPOSE 90

# Set the default command to execute
# when creating a new container
CMD service nginx start

我的nginx.conf有以下观点:

worker_processes  1;

events {
    worker_connections  1024;
}

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

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       9000;
        server_name  localhost;
        error_log  /var/log/nginx/error.log;
        index login.html;
        root /usr/share/nginx/html/;
    }
}

在路径Front-Dev/v2/desktop中有login.html个文件。

通过以下命令成功构建了Docker镜像:sudo docker build --rm -t pitstop-nginx .

Docker容器由sudo docker run -p 9000:90 pitstop-nginx执行,我在sudo docker ps

中看到了

但是,当我转到http://localhost:9000/http://localhost:9000/login.html时,没有任何内容。我做错了什么?

1 个答案:

答案 0 :(得分:0)

你的nginx conf文件正在使用端口9000,你正在暴露端口90。

它不起作用。

如果你的nginx使用端口9000,你应该公开它。然后映射它。

sudo docker run -p 9000:9000 pitstop-nginx

-p localhost_port:container_port