首页 文章

Docker上的端口

提问于
浏览
1

有没有办法将端口绑定到容器而不通过run命令传递参数?我不喜欢用'docker run'命令启动我的容器,所以使用-p参数对我来说不是一个选项 . 我喜欢使用'docker start containername'命令启动容器 . 我想用端口号(http://dockerserver:8081)指定docker-server的主机名,然后将其转发到我的容器's app which is listening on port 8081. My setup is on Azure but is pretty basic so the Azure docker plugin looks a bit like overkill. I read up about the expose command but seems like you still need to use the ' docker run -p'命令以从外部访问容器 . 任何建议将非常感谢 .

1 回答

  • 2

    docker run 只是 docker create docker start 的快捷方式 . 创建容器时需要公开端口,因此docker create中的 -p 选项可用:

    docker create -d -p 80:80 --name web nginx:alpine
    docker start web
    

    端口发布只做端口 .

    如果您希望将主机名传递给容器,则需要使用命令选项或(更可能)环境变量 - 在Dockerfile中使用 ENV 定义并在 docker create 中使用 -e 传递 .

相关问题