3

When I call the docker run command in my terminal. The server starts up fine and is accessible, but when I try to add the port in the dockerfile. It does not work.

Is there a way I can set the port in the dockerfile explicitly? Thanks for any help.

This works:

docker run -d -p 5555:4444 -v /dv/sm:/dv/sm sa:latest

I remove the -p flag and try to "pass" it in via the docker file, but it does not work (error: This site can’t be reached)

Not working:

docker run -d -v /dv/sm:/dv/sm sa:latest

I've tried - Docker file:

FROM WorkingTestImage as MyImage
ENTRYPOINT "/opt/bin/entry_point.sh"
CMD ["-p","5555:4444"]

FROM WorkingTestImage as MyImage
ENTRYPOINT ["/opt/bin/entry_point.sh","-p","5555:4444"]
CMD ["-p","5555:4444"]

FROM WorkingTestImage as MyImage
ENTRYPOINT ["/opt/bin/entry_point.sh","-p","5555:4444"]
1
  • Not possible. You have to specify the -p option on the docker run command.
    – Henry
    Feb 28, 2019 at 4:39

1 Answer 1

2

The -p option is specifically used with the docker command meanwhile the CMD in Dockerfile just runs a command inside the docker container when it runs. So it is out of the scope from "docker" command.

If you want to write the port as a code you need to use Docker Compose or Kubernetes.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.