全新 Ubuntu 14.04.2 Docker 容器 + Nginx:端口 80 上的连接被拒绝
Brand new Ubuntu 14.04.2 Docker container + Nginx: connection refused on port 80
我按照 Digital Ocean's "How To Install Nginx on Ubuntu 14.04 LTS" 上的说明进行操作,其中指出 Nginx 应该 运行 安装后,但是下面的 Docker 文件:
FROM ubuntu:14.04.2
RUN apt-get update -y
RUN apt-get -y install curl
RUN apt-get -y install nginx
RUN curl http://127.0.0.1 | grep "Welcome to nginx!"
给我这个错误:
curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused
要重现此内容:
- 确保 Docker 安装在您的主机系统上
- 将上面的代码插入
/whatever/path/Dockerfile
- 输入'cd /whatever/path/ && Docker build .'
这将使用 Ubuntu 构建 docker 容器,安装 Nginx,然后尝试连接到 127.0.0.1:80 returns Nginx 欢迎页面。这就是 "connection refused" 错误发生的地方。
我的问题是:如何从我的容器中调用“curl http://127.0.0.1 并获得响应?
我项目中的这个问题是https://github.com/dcycleproject/dcyclebox/issues/1
数字海洋说明 OS 与 运行ning 服务不在 docker 容器中 运行ning(它们不应该)。构建映像时,您只需安装必要的软件。那么你应该 运行 基于这个图像的容器 - 通常只有一个进程是 运行ning 在容器中。例如查看官方 nginx 图像 - https://github.com/dockerfile/nginx/blob/master/Dockerfile
此外,在不同的 运行 命令中 运行 apt-get update 和 apt-get install 也是一种不好的做法 - https://docs.docker.com/articles/dockerfile_best-practices/#run
别忘了先开始nginx
:
RUN service nginx start && curl http://127.0.0.1 | grep "Welcome to nginx!"
我按照 Digital Ocean's "How To Install Nginx on Ubuntu 14.04 LTS" 上的说明进行操作,其中指出 Nginx 应该 运行 安装后,但是下面的 Docker 文件:
FROM ubuntu:14.04.2
RUN apt-get update -y
RUN apt-get -y install curl
RUN apt-get -y install nginx
RUN curl http://127.0.0.1 | grep "Welcome to nginx!"
给我这个错误:
curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused
要重现此内容:
- 确保 Docker 安装在您的主机系统上
- 将上面的代码插入
/whatever/path/Dockerfile
- 输入'cd /whatever/path/ && Docker build .'
这将使用 Ubuntu 构建 docker 容器,安装 Nginx,然后尝试连接到 127.0.0.1:80 returns Nginx 欢迎页面。这就是 "connection refused" 错误发生的地方。
我的问题是:如何从我的容器中调用“curl http://127.0.0.1 并获得响应?
我项目中的这个问题是https://github.com/dcycleproject/dcyclebox/issues/1
数字海洋说明 OS 与 运行ning 服务不在 docker 容器中 运行ning(它们不应该)。构建映像时,您只需安装必要的软件。那么你应该 运行 基于这个图像的容器 - 通常只有一个进程是 运行ning 在容器中。例如查看官方 nginx 图像 - https://github.com/dockerfile/nginx/blob/master/Dockerfile
此外,在不同的 运行 命令中 运行 apt-get update 和 apt-get install 也是一种不好的做法 - https://docs.docker.com/articles/dockerfile_best-practices/#run
别忘了先开始nginx
:
RUN service nginx start && curl http://127.0.0.1 | grep "Welcome to nginx!"