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链接时,什么都没有。我做错了什么?

您的nginx conf文件正在使用端口9000,并且您正在公开端口90。

这是行不通的。

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

sudo docker run -p 9000:9000 pitstop-nginx

-p localhost_port:container_port

最新更新