Why cannot access a running Docker container in browser?

Question:

Here is my dockerfile:

FROM python:3.8

WORKDIR /locust

RUN pip3 install locust

COPY ./ /locust/

EXPOSE 8089

CMD ["locust", "-f", "locustfile.py"]

Here is the response:

Starting web interface at http://0.0.0.0:8089 (accepting connections from all network interfaces)
Starting Locust 1.2.3

But when I try to access it in the browser – it doesn’t load. I feel like I might be missing something simple, but cannot find it.

Asked By: D_Asti

||

Answers:

This statement,

EXPOSE 8089

will only expose your port for inter-container communication, but not to the host.

For allowing host to communicate on the container port you will need to bind the port of host and container in the docker run command as follows

docker run -p <HOST_PORT>:<CONTAINER:PORT> IMAGE_NAME

which in your case will be

docker run -p 8089:8089 IMAGE_NAME
Answered By: Aayush Mall
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.