도커 컨테이너에서 도커 호스트로 연결

도커 컨테이너에서 도커 호스트로 연결

내 웹사이트의 모든 부분을 Docker 컨테이너에서 실행하는 설정이 있습니다. 포트 80 및 443에서 수신 대기하는 내 nginx는 컨테이너에서 실행됩니다.

363292a98545        scivm/nginx-django-scivmcom:latest   /usr/bin/supervisord   12 days ago         Ghost               0.0.0.0:40001->22/tcp, 88.198.57.112:443->443/tcp, 88.198.57.112:80->80/tcp     lonely_feynmann           

다른 컨테이너의 서비스에 대한 프록시를 설정하고 싶습니다. 이 컨테이너는 호스트의 포트 3000에 바인딩됩니다.

b38c8ef72d0a        mazzolino/strider-dind:latest        wrapdocker /usr/bin/   41 minutes ago      Up 41 minutes       0.0.0.0:3000->3000/tcp, 22/tcp, 27017/tcp                                       distracted_einstein      

Docker 호스트의 내 iptables는 다음과 같습니다.

root@Ubuntu-1204-precise-64-minimal /var/run # iptables -L
Chain INPUT (policy ACCEPT) target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:8000
DROP       all  --  anywhere             anywhere            

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

iptables 구성으로 인해 컨테이너 내에서 호스트 시스템의 포트 3000에 연결할 수 없습니다.

공용 인터넷에 포트 3000을 열고 싶지 않습니다.

포트 3000에서 컨테이너와 호스트 사이에 직접 브리지를 여는 방법이 있습니까?

아니면 docker IP 범위에서 허용하도록 iptables를 수정해야 합니까?

답변1

필요한 것은 Docker뿐입니다.링크 기능[지원 중단됨]

시도했던 모든 복잡한 작업을 제거하고 명명된 컨테이너를 사용하기 시작한 다음 서로 연결하십시오.

답변2

Elias의 답변은 정확하지만 링크가 길고 혼란스럽습니다. 다음은 간단한 요약입니다.

먼저 연결할 컨테이너를 실행하고 이름을 지정합니다.

sudo docker run -d --name db training/postgres

그런 다음 다른 컨테이너를 실행하여 첫 번째 컨테이너에 연결합니다.

sudo docker run -d -P --name web --link db:db training/webapp python app.py

첫 번째 컨테이너에서 두 번째 컨테이너로의 링크는 /etc/hosts. 따라서 호스트 이름처럼 사용할 수 있습니다. 예를 들어:

sudo docker run --name web --link db:db training/webapp ping db

관련 정보