Why cannot access a running Docker container in browser?

2.7k views Asked by At

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.

1

There are 1 answers

0
Aayush Mall On BEST ANSWER

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