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?

  • 'docker push …' from Bitbucket Pipelines is very slow to my self-hosted docker registry
  • How to create a docker container out of existing project on Ubuntu
  • Simple way to run subdomains on docker container in developer environment
  • Logging solution for multiple containers running on same host
  • envsubst command getting stuck in a container
  • deploy docker to heroku without using heroku docker plugin
  • Pseudo-tty with Fig/Docker container
  • Is there any way to get logs in Docker Swarm?
  • hazelcast docker container can't run continuously
  • Isolate PHP versions on AWS EC2
  • install java successfully using the dockerfile however its says java command not found
  • How to edit code in a Docker container in development?
  • 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.