【问题标题】:Expose and publish a port with specified host port number inside Dockerfile在 Dockerfile 中公开并发布具有指定主机端口号的端口
【发布时间】:2016-05-20 18:27:16
【问题描述】:

例如,假设我想在 Docker 中创建一个 SSH 主机。我知道我可以在Dockerfile 中使用EXPOSE 22。我也知道我可以使用-p 22222:22,所以我可以从我的局域网上的另一台物理机器上的端口 22222 以ssh my_username@docker_host_ip -p 22222:22 SSH 到该 Docker 容器。但是假设我太懒了,以至于我每次都懒得去docker run这个带有选项-p 22222:22的容器。有没有办法让选项-p 22222:22 can be automated in a config file somewhere? InDockerfile` 可能?

【问题讨论】:

    标签: ssh docker


    【解决方案1】:

    您可以使用docker compose

    您可以在docker-compose.yml文件中定义监听端口,如下:

    version: '2'
    services:
      web:
        image: ubuntu
      ssh_service:
        build: .
        command: ssh ....
        volumes:
          - .:/code
        ports:
          - "22222:22"
        depends_on:
          - web
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-29
      • 2021-12-10
      相关资源
      最近更新 更多