Kiran
Kiran

Reputation: 151

is there a way to do bind particular port on host to container port using docker file

is there a way to do bind particular port on host to container port using docker file

I have following item in docker file Step 1 : EXPOSE 8090:8080

but when i run docker run, container binds to port 8080 instead of 8090 as described in docker file.

any idea how i can achieve this using docker file or is there any better way to achieve this.

Upvotes: 0

Views: 221

Answers (2)

gabrtv
gabrtv

Reputation: 3588

is there a way to do bind particular port on host to container port using docker file

No. The Dockerfile is designed to include only portable configuration. Binding to a host port is not portable because the host port may not be available on every system. These configuration flags may be available at runtime, but are not included in the Dockerfile syntax (and resulting Docker images).

Under the hood, host ports and other non-portable configuration (e.g. volume mounts) are part of the HostConfig structure of the container. These are only available at container runtime.

Upvotes: 0

czerasz
czerasz

Reputation: 14250

Can't see that docker implements the EXPOSE feature as You described it.

From the documentation:

EXPOSE

EXPOSE <port> [<port>...]

The EXPOSE instructions informs Docker that the container will listen on the specified network ports at runtime. Docker uses this information to interconnect containers using links (see the Docker User Guide).

EXPOSE isn't an equivalent for the vagrant forwarded_port functionality.

It's useful when You need to link containers.

If You need to forward a port from the container to the host use the -p flag.
Example:

docker run -it -p 80:80 5959f94a4d10 /bin/bash

Upvotes: 1

Related Questions