3

I have two nginx containers running.

One is listening on port 80 the other 8080.

Here is how I run them:

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

The second:

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 config:

location / {
    proxy_pass http://10.88.0.37:8080;
}

I also tried:

location / {
    proxy_pass http://127.0.0.1:8080;
}

This config is used by the --name=nginx container.

Here is the error I get:

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" "-"

Is there way to make these containers communicate with each other?

I also tried using --pod. But then got this error:

Error: cannot set port bindings on an existing container network namespace
1
  • Did you solve this? – codezombie May 1 '20 at 19:53
0

You should not use --publish-all, as the man page of podman-run indicates this publishes all exposed ports to random ports of the host interface. The -p option is therefore sufficient.

Creating a dedicated network where both containers would be could help with your issue, you could then reference it by using the --network=network-id option of the run command.

When using pods, the port mappings should be defined on the pod itself, not on the containers within that pod:

podman pod create --name mypod -p 80:80

It would not be possible to run in a single pod with two nginx instances due to conflicting ports 80. (it uses the exposed ports of the image)

Red Hat published a good explanation: https://www.redhat.com/sysadmin/container-networking-podman

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.