0

If I have a container that I run as follows:

docker run -d\
 --name thename\
 --restart=always\
 -p 80:80\
 -p 2003-2004:2003-2004\
 -p 8126:8126\
image_name

How can I create a docker file so that the container runs exactly as above without needing to specify anything but the following: docker run -d myimage?

4

1 回答 1

1

AFAIK,您无法使用 Dockerfile 管理容器名称、重启策略和主机端口。

我建议你去 docker compose。您可以在 YML 文件中定义以上所有内容并运行如下命令以获得您期望的确切行为 -

$ docker-compose up -d

示例 YML -

version: '3'
services:
  web:
    build: .
    container_name: thename
    restart: always
    ports:
     - "80:80"
     - "8126:8126"
     - "2003-2004:2003-2004"

参考 - https://docs.docker.com/compose/compose-file/

于 2018-12-07T09:32:19.337 回答