1

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"]
user_76541
  • 33
  • 1
  • 4

1 Answers1

1

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.

inductor
  • 64
  • 3