2

I have to run a container running nginx as a reverse proxy using podman.

Dockerfile is as follows:

FROM nginx

COPY nginx/* /etc/nginx/

Where basically I have a default.conf file under conf.d which is like this:

server {

    listen       80;
    server_name  my-server;

    client_max_body_size 200M;

    location / {
        root /usr/share/nginx/html;
    }

    location /api {
        proxy_set_header X-FORWARDED-FOR $remote_addr;
        proxy_pass http://backend:3300/api;
    }

    error_page  404              /;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

where backend is an alias for another container with a rest server running on the same network that contains the proxy.

I setup the network with the command:

podman create custom-network

then I run the following command:

podman run -d --name=frontend -p 80:80 --network=custom-network:alias=frontend -v ./www:/usr/share/nginx/html -v ./logs:/var/log/nginx localhost/my-www:latest 

At this point everything is up and running and I can open my application from the browser in the same machine, but it is unreachable from another computer on the same network.

I already turned off windows firewall on every network, but still nothing.

Is there a podman command or a configuration tweak that make nginx container reachable from outside?

3
  • Read this github.com/containers/podman/blob/main/rootless.md. TLDR: using port below 1024 requires root. Try using 8080, if it works, you know where the problem is, couple googles and you should be good to go. Good luck.
    – Kyslik
    Commented Jul 8, 2023 at 20:06
  • Thank you, but if that was the case the cointainer would fail to run right? In my case the container is running fine and i can access everything from localhost. The problem rises when i try from another computer on the same network, no port exposed, no access log in nginx, nothing. It's not just listening on any network other than 127.0.0.1 Commented Jul 10, 2023 at 6:20
  • I wrote an example of how to run socket-activated nginx proxy with podman github.com/eriksjolund/podman-nginx-socket-activation/tree/main/… The example uses the systemd directive User=, but that could be skipped to make the example less experimental. Commented Dec 13, 2023 at 20:11

1 Answer 1

2

I ran into this same issue on windows and since you mentioned windows firewall I am assuming you are also running it.

I noticed that you did not mention any portmapping.

Get the ip of your podman vm. podman machine ssh and then an ifconfig. Then you just map your port like below to your vm ip and your requests from outside should work.

netsh interface portproxy add v4tov4 listenport=<hostport> listenaddress=0.0.0.0 connectport=<containerPORT> connectaddress=172.26.29.96

4
  • 1
    this is exactly what i did to fix the issue. good call Commented Nov 13, 2023 at 9:49
  • Hope you didn't waste too much time figuring it out. Maybe mark this as the answer so the next folks can find it faster. :-) Now if I can figure this out on a fedora box...
    – eddyizm
    Commented Nov 13, 2023 at 21:43
  • I ran the command you wrote(also could be found here learn.microsoft.com/en-us/windows/wsl/…) but it didn't work! should I do something after running this command? like restarting something? for DockerDesktop it isn't like that and it just works! why for podman it need this forwarding?
    – Parsa
    Commented May 20 at 19:42
  • 1
    @Parsa What does your netsh show? Is your ip correct and did you disable the firewall because I believe that could block it? I think this works differently because of the networking, for me, I am running rootless. I am sure Docker desktop is using a different network mode, you can do that as well for podman however if you run a lot of containers its better to be in their own isolated networks.
    – eddyizm
    Commented May 28 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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