Docker Community Forums

Share and learn in the Docker community.

Container with internal IP for Nginx and external IP for LAN access?


#1

Hello,

I know the topic sounds a bit chaotic. But I didn’t know how to describe it better…

I’m currently trying to build some home automation stuff with docker.

For access of most thing I want to use a NGINX reverse proxy. So most of the containers I have need no network access. I only need them to be reachable for the other containers.

But there is on container which is a bit problematic.

The service running in that container needs to be using the ports 80/443. The same as NGINX needs.
I need to rech that container from some other containers, from the NGINX container and from the LAN network.

I originally had everything hosted without docker but after I needed the ports twice I just set up the problematic component with docker and gave it its own LAN IP by using ‘macvlan’.

But then I can acces it from the network but not from the device itself. Because of the limitations of ‘macvlan’ itself.
So I figured I should just put everything into docker containers because it should be possible that way?
Maybe by doing something like an internal network between the containers and then use the ‘macvlan’ thing to give IPs to the 2 containers I actually need to reach from the network?

But I honestly don’t know how to do that.
Is there any place where I can read about how to set up something like that? Or some ressources where I can learn about the components I need?

I would really appreciate some help in this.

Greeting,
Daniel :slight_smile:


(Paulxroot) #2

Hi Daniel,

you can map your nginx ports to different ports than 80 and 443 when publishing them with docker.
docker run --name some-nginx -d -p 10080:80 -p 10443:443 nginx
Will make nginx’s internal port 80 accesible on port 10080 and 443 on 10443 on the host machine.
I had some inspiration at the nginx docker documentation: https://hub.docker.com/_/nginx/

That’s only possible if you can change the port that the applications that need to access the nginx’s HTTP service from outside the docker network want to connect to. But this would be the simplest solution in my eyes.


#3

I already found a solution that works for me.

I creted a bridge network which all my containers connect to and use to communicate with each other.

And then I created another network using the macvlan driver and connected the 2 containers I needed outside communication to.
I assigned them each a static ip and now everything works as it’s supposed to work. Or at least it does so far :smiley: