【发布时间】:2016-05-11 07:41:01
【问题描述】:
我有一个托管在 Docker 中的纯前端 Web 应用程序。后端已经存在,但它有“自定义 IP”地址,所以我必须更新我的本地 /etc/hosts 文件才能访问它。所以,从我的本地机器上,我可以毫无问题地访问后端 API。
但问题是 Docker 不知何故无法解析这个“自定义 IP”,即使主机写入容器(图像?)/etc/hosts 文件中也是如此。
当 Docker 容器启动时,我看到了这个错误
$ docker run media-saturn:dev
2016/05/11 07:26:46 [emerg] 1#1: host not found in upstream "my-server-address.com" in /etc/nginx/sites/ms.dev.my-company.com:36
nginx: [emerg] host not found in upstream "my-server-address.com" in /etc/nginx/sites/ms.dev.my-company.com:36
我通过 Dockerfile 中的命令更新 /etc/hosts 文件,像这样
# install wget
RUN apt-get update \
&& apt-get install -y wget \
&& rm -rf /var/lib/apt/lists/*
# The trick is to add the hostname on the same line as you use it, otherwise the hosts file will get reset, since every RUN command starts a new intermediate container
# it has to be https otherwise authentification is required
RUN echo "123.45.123.45 my-server-address.com" >> /etc/hosts && wget https://my-server-address.com
当我 ssh 进入机器查看 /etc/hosts 的当前内容时,确实存在“123.45.123.45 my-server-address.com”这一行。
谁能帮我解决这个问题?我是 Docker 新手。
【问题讨论】:
-
您收到什么错误信息?您是否支持代理?
-
@VonC 错误信息是
host not found in upstream "ms-test.internal.pricefx.eu" in /etc/nginx/sites/ms.dev.topmonks.com:36(上面已经提到过)。没有代理 -
你使用什么命令来构建你的镜像? (意思是,您是否构建了标记为
media-saturn:dev的图像,其中wget ms-test.internal.pricefx.eu成功了?) -
尝试仅先运行 bash
docker run -it media-saturn:dev /bin/bash如果它在图像中。检查您是否真的可以解析 dns。
标签: nginx docker dockerfile