'Is there a way to forward a port from Docker to a custom address on host's machine?

I am currently trying to forward a port from a Docker container to my local machine. I am running the following command:

docker run -itp jupyterhub.localhost:80:8000 --name jupyterhub bitnami/jupyterhub sudo jupyterhub

But I am getting this error:

docker: Invalid ip address: jupyterhub.localhost.

Basically, I want the container to be forwarded to the jupyterhub.localhost:80 address. Is this possible to do with Docker?



Solution 1:[1]

Since docker doesn't bind hostnames, I would recommend to find the ip address that the hostname jupyterhub.localhost resolves to. From your docker host, run

host jupyterhub.localhost

This command will return the <IP_ADDRESS>, then initiate your container

docker run -itp <IP_ADDRESS>:80:8000 --name jupyterhub bitnami/jupyterhub sudo jupyterhub

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tolis Gerodimos