두 개의 다른 웹 응용 프로그램을 실행하는 두 개의 컨테이너를 만들었습니다. 나는 호스트 이름에 따라 올바른 컨테이너에 요청을 리디렉션 nginx 프록시가 세 번째 컨테이너를 만들려고 해요. 내 Nginx 구성은 nginx 공식 이미지를 실행하고 프록시 설정을 사용하여 컨테이너 내부의 기본 구성 파일을 수동으로 수정할 때 올바르게 나타납니다. 다른 도커 컨테이너에 연결된 Nginx 프록시
내 두 개의 웹 응용 프로그램을
컨테이너가 이미 실행하고, 나는 다음과 같이 프록시 컨테이너를 시작 : 내가 생각하는docker run -i -t --link webapp1 --link webapp2 -p 80:80 nginx /bin/bash
이, 가장 깨끗한 방법을 이렇게하려면 내가 컨테이너를 만들 Dockerfile을 만들 것, 그리고 빌드 할 때 로컬 default.conf 파일을 컨테이너에 전달합니다.
이 내의 nginx 프록시 구성 파일입니다
server {
listen 80;
server_name www.webapp1.ch;
location/{
proxy_pass http://webapp1/;
}
}
server {
listen 80;
server_name www.webapp2.ch;
location/{
proxy_pass http://webapp2/;
}
}
그리고 프록시 고정 표시기 파일 :
# Set the base image to use to Ubuntu
FROM nginx:latest
# Set the file maintainer (your name - the file's author)
MAINTAINER Me
# Update the default application repository sources list
RUN apt-get update && apt-get install -y \
wget \
vim
RUN rm /etc/nginx/conf.d/default.conf
COPY default /etc/nginx/conf.d/default.conf
CMD /etc/init.d/nginx restart
그러나 나는 그것을 만들려고 할 때 불행하게도, 컨테이너가 모르는 webapp1 및 webapp2 컨테이너는 아직 링크되지 않았으므로/ip를 주소 지정합니다. 이 오류가 나타납니다.
Step 7 : RUN /etc/init.d/nginx restart
---> Running in aef974e80e74
Restarting nginx: nginx2016/12/29 17:07:17 [emerg] 11#11: host not found in upstream "webapp1" in /etc/nginx/conf.d/default.conf:6
nginx: [emerg] host not found in upstream "webapp1" in /etc/nginx/conf.d/default.conf:6
nginx: configuration file /etc/nginx/nginx.conf test failed
무엇이 잘못 되었습니까? 그리고 그것을 해결하는 가장 좋은 방법은 무엇입니까?
감사합니다. Farhad, 귀하의 답변을 확인한 결과 제안 된대로 네트워크를 생성하여 수정했습니다. 이제 잘 작동합니다. – Fab