简体   繁体   中英

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? In -p 22222:22 can be automated in a config file somewhere? In Dockerfile` maybe?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM