[英]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. 例如,假设我想在Docker中建立一个SSH主机。 I understand that I can EXPOSE 22
inside Dockerfile
. 我知道我可以在Dockerfile
EXPOSE 22
。 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
. 我也了解我可以使用-p 22222:22
因此可以从我的LAN在端口22222上的另一台物理计算机上通过ssh my_username@docker_host_ip -p 22222:22
SSH到该Docker容器中。 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. 但是,假设我是如此懒惰,以至于我每次都不必为docker run
带有-p 22222:22
选项的容器而烦恼。 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
选项-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? -p 22222:22 can be automated in a config file somewhere? In
Dockerfile中吗?
You can use docker compose 您可以使用docker compose
You can defind listening port in docker-compose.yml
file as below: 您可以在docker-compose.yml
文件中定义监听端口,如下所示:
version: '2'
services:
web:
image: ubuntu
ssh_service:
build: .
command: ssh ....
volumes:
- .:/code
ports:
- "22222:22"
depends_on:
- web
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.