
두 개의 nginx 컨테이너가 실행 중입니다.
하나는 포트 80에서 다른 하나는 8080을 수신합니다.
실행 방법은 다음과 같습니다.
sudo podman run --rm \
-t \
-p 8080:80 \
--publish-all \
--name nginx-two \
-v ./html2/:/usr/share/nginx/html \
-v ./html2/conf/default.conf:/etc/nginx/conf.d/default.conf \
-d nginx
두번째:
sudo podman run --rm -t -p 80:80 --name nginx -v ./html/:/usr/share/nginx/html -v ./html/conf/conf.d:/etc/nginx/conf.d -d nginx
NGiNX 구성:
location / {
proxy_pass http://10.88.0.37:8080;
}
나는 또한 다음을 시도했습니다.
location / {
proxy_pass http://127.0.0.1:8080;
}
이 구성은 컨테이너에서 사용됩니다 --name=nginx
.
내가 얻는 오류는 다음과 같습니다.
2020/01/26 15:33:05 [error] 8#8: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 10.88.0.1, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "localhost"
10.88.0.1 - - [26/Jan/2020:15:33:05 +0000] "GET / HTTP/1.1" 502 157 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0" "-"
이러한 컨테이너가 서로 통신할 수 있는 방법이 있습니까?
을 사용해 보기도 했습니다 --pod
. 그런데 다음과 같은 오류가 발생했습니다.
Error: cannot set port bindings on an existing container network namespace
답변1
--publish-all
podman-run의 매뉴얼 페이지에는 노출된 모든 포트가 호스트 인터페이스의 임의 포트에 게시된다는 내용이 나와 있으므로 를 사용해서는 안 됩니다 . 따라서 옵션 -p
으로 충분합니다.
두 컨테이너가 모두 문제 해결에 도움이 될 수 있는 전용 네트워크를 생성한 다음 --network=network-id
명령 옵션을 사용하여 이를 참조할 수 있습니다 run
.
포드를 사용할 때 포트 매핑은 해당 포드 내의 컨테이너가 아닌 포드 자체에서 정의되어야 합니다.
podman pod create --name mypod -p 80:80
포트 80 충돌로 인해 두 개의 nginx 인스턴스가 있는 단일 Pod에서 실행할 수 없습니다. (이미지의 노출된 포트를 사용합니다)
Red Hat은 좋은 설명을 게시했습니다.https://www.redhat.com/sysadmin/container-networking-podman