How to use port mapping / forwarding

hello everyone

just a short question and I imagine it is quite simple but I cannot get it right:
let’s say I deploy a container that runs normally on port 8000. Since port 8000 is already used by another app I wanna map that port to 8001 (as when starting a container just by using docker cli)

so creating a new contrainer (I use portainer for this) and map ports --> host: 8001 --> container: 8000

that’s how I tried it and it still creates the container only accessible over webgui on port 8000 …

maybe some information that is needed to solve this: i start my containers in the network “host” so that they are accessible over the IP of the host (i.e. something like 192.168.1.XXX instead of docker’s IP 172.17.0.1) …

does anyone know what im understanding wrong here?

thanks for your help

There is no such thing as publishing ports if the container is running with --network host, all ports occupied by processes in the container will be directly bound to a host port.

If you want to publish ports, you will need to use a bridged or overlay network.

thank you for the answer meyay! i was thinking that the problem might be there…

so that’s the thing then: I use network “host” so that I can access the container over the IP address of the VM. might you be able to explain to me how I can achieve that without using --network host?

thanks so much and best regards

I will leave this one to others.

Though, If you actualy want to learn docker, I can highly recommend this excellent free self-paced training: https://container.training/intro-selfpaced.yml.html. Docker makes more fun, if you actualy know how it works and needs to be used, instead of having to rely on forums to solve your problem of the hour…

hey again

thanks, I will do that and answer my question as soon as I find the solutions so others might find it in the future!

best regards