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?

  • Mount host directory with a symbolic link inside in docker container
  • How to overwrite default command when running docker image
  • How to optimise docker pull speed
  • Where is the time spent starting a docker image?
  • Is it possible to mount a docker image and then access it (RO) as a normal directory or mounted device?
  • How to persist 'ln' in Docker with Ubuntu
  • Enable webcam in docker application and access thru AWS ECS
  • docker container in AWS VPC, good idea or not? [closed]
  • How to connect postgresql container to django container?
  • Ignite on Docker
  • Using Amazon ECS with google container registry
  • CircleCI: Best way to verify if docker containers are responding via HTTP
  • 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'
    services:
      web:
        image: ubuntu
      ssh_service:
        build: .
        command: ssh ....
        volumes:
          - .:/code
        ports:
          - "22222:22"
        depends_on:
          - web
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.