supritshah1289
supritshah1289

Reputation: 849

I cannot access proxy of a running docker container

I have a running Docker container which shows PORTS 9191/tcp. So on my browser, I tried accessing server using localhost:9191/api/.... However, browser throws an error This site can’t be reached

Here is a log to docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c214aefed15e shah "youtube-dl-server -…" 6 seconds ago Up 5 seconds 9191/tcp boring_swirles

This is what my docker file looks like

FROM mariozig/youtube-dl_server RUN pip install --pre youtube_dl_server EXPOSE 9191 ENTRYPOINT ["youtube-dl-server", "--host=0.0.0.0"]

Upvotes: 0

Views: 829

Answers (1)

YK S
YK S

Reputation: 3440

You have not mapped the docker container port to host port.

The docker container runs on a host. And The host doesn't know which requests to be directed to the docker container. For that you have to to map the host port to docker container port using -p flag in docker run command as shown below:

docker run -d -p HOST_PORT:CONTAINER_PORT IMAGE_NAME

-p in this command will specify that you are forwarding your host port to the container port. In your local host in the port HOST_PORT will call the port CONTAINER_PORT of your container.

Now when you will access the HOST_IP:HOST_PORT then the host will redirect the request to corresponding container with which this HOST_PORT has been mapped.

For example I started a tomcat docker container and mapped the tomcat container's 8080 port to host's 9092 port by using the above command. When I do docker ps I can see the mapping under PORTS as 0.0.0.0:9092->8080/tcp

Upvotes: 1

Related Questions