Expose and publish a port with specified host port number inside Dockerfile

Suppose for example that I want to make an SSH host in Docker. I understand that I can EXPOSE 22 inside Dockerfile. I also understand that I can use -p 22222:22 so I can SSH into that Docker container from another physical machine on my LAN on port 22222 as ssh my_username@docker_host_ip -p 22222:22. But suppose that I’m so lazy that I can’t be bothered to docker run the container with the option -p 22222:22 every time. Is there a way that the option -p 22222:22 can be automated in a config file somewhere? InDockerfile` maybe?

  • Tomcat + MySQL docker container outputting utf8 text with wrong encoding
  • Kubernetes save JSON logs to file with escaped quotes. Why?
  • Cannot use process substitution during docker build because bash goes into posix mode
  • Docker - Fail to run container from imported image with entrypoint
  • How to create a docker container out of existing project on Ubuntu
  • kafka on kubernetes cannot produce/consume topics (ClosedChannelException, ErrorLoggingCallback)
  • Cannot produce message to kafka from service running in docker
  • Official Jenkins Dockerfile acting strange
  • how to ssh docker container
  • How to build docker image for a spring boot application jar?
  • Sonar qualityprofile page does not display correctly using docker when data volume is mounted from disk.
  • What are the differences between a VM image and a Docker image? [duplicate]
  • One Solution collect form web for “Expose and publish a port with specified host port number inside Dockerfile”

    You can use docker compose

    You can defind listening port in docker-compose.yml file as below:

    version: '2'
        image: ubuntu
        build: .
        command: ssh ....
          - .:/code
          - "22222:22"
          - web
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.