Reputation: 39
I am new to Docker.
I was trying to dockerize a simple static website using nginx base image. The applicatio runs fine on local server when i run.
docker run -d -P <container-name>
So, here the app runs on some random port on which i am able to see my app running.
while, when i try to specify port by using the following command:
docker run -d -p 5000:5000 --restart=always --name app mkd63/leo-electricals
The page at localhost:5000 shows site cant be reached.
My Dockerfile is:
FROM nginx:alpine
COPY . /usr/share/nginx/html
EXPOSE 5000
Upvotes: 0
Views: 7454
Reputation: 264426
By default, the nginx image listens on port 80 inside the container.
Publishing a port creates a port forward from the host into the container. This doesn't modify what port the application is listening on inside the container, so if you forward to an unused port, you won't connect to anything.
Exposing a port in the Dockerfile is documentation by the image creator to those running the image, but doesn't modify container networking or have any control over what the application running inside the container is doing. With docker, the -P
flag uses that documentation to publish every exposed port.
To map port 5000 on the host to nginx listening on port 80 inside the container, use:
docker run -d -p 5000:80 --restart=always --name app mkd63/leo-electric
Upvotes: 3