我有以下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
时,没有任何内容。我做错了什么?
答案 0 :(得分:0)
你的nginx conf文件正在使用端口9000,你正在暴露端口90。
它不起作用。
如果你的nginx使用端口9000,你应该公开它。然后映射它。
sudo docker run -p 9000:9000 pitstop-nginx
-p localhost_port:container_port