我正在尝试获取nginx的默认网页,但在容器运行后无法通过http连接端口80。
我正在运行docker 1.9.9版本。
我所采取的步骤如下:
首先创建了一个Docker文件:
FROM ubuntu:15.10
RUN echo "Europe/London" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get install -y nginx
RUN apt-get install -y supervisor
RUN apt-get update && apt-get -q -y install lsof
RUN apt-get install net-tools
RUN apt-get install psmisc
RUN apt-get -y install curl
ADD supervisor.nginx.conf /etc/supervisor.d/nginx.conf
CMD /usr/bin/supervisord -n
RUN rm -Rf /etc/nginx/conf.d/*
RUN rm /etc/nginx/sites-enabled/default
RUN mkdir /etc/nginx/logs/
RUN touch /etc/nginx/logs/error.log
RUN mkdir /usr/share/nginx/logs/
RUN touch /usr/share/nginx/logs/error.log
ADD ./conf/nginx.conf /etc/nginx/sites-available/default
RUN ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
copy ./dist /usr/share/nginx/html
CMD /usr/bin/supervisord -n
Docker文件将下面的nginx配置文件复制到
/etc/nginx/sites-available/default
,并为/etc/nginx/sites-enabled/default
创建了一个符号链接。server {
root /usr/share/nginx/html;
index index.html index.htm;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 5d;
}
# deny access to . files, for security
#
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
}
然后我使用以下命令构建了镜像:
docker build -t dnginx
我使用以下命令启动了容器:
docker run --name d3 -d -p 80:80 dnginx
我找到了IP地址并尝试连接。
curl http://172.17.0.2
涉及技术内容,需要翻译如下:
出现了如下错误信息:
curl: (7) Failed to connect to 172.17.0.2 port 80: Operation timed out
我在容器中打开了bash shell并运行了nginx
,结果如下:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
如果我运行
netstat --listen
,我会得到以下结果:Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:80 *:* LISTEN
如果我运行
netstat -ltnp | grep :80
,我会得到以下结果:tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -
我完全不知道正在发生什么。
如果我只连接到nginx镜像,同样的事情也会发生。
sudo netstat -ltnp | grep :80
来实现。一旦您了解了它是哪个进程,如果您对它不感兴趣,可以将其终止并重试。 - mgaido