【问题标题】:What is the difference between the "command" parameter in the docker-compose.yml and the CMD parameter in the Dockerfile?docker-compose.yml 中的“command”参数和 Dockerfile 中的 CMD 参数有什么区别?
【发布时间】:2021-12-07 07:32:23
【问题描述】:

如您所知,在 Dockerfile 中,您可以通过 RUN 和 CMD 参数指定命令(示例如下)。

...
RUN pip3 install --upgrade pip
RUN pip3 install pytest
...
CMD ["python3", "main.py"]
...

docker-compose.yml中,也可以指定命令参数(示例如下)。

...

services:
    conteiner_a:
        ...
        command: ["echo", "!!!!!!!! Container_A is available now !!!!!!!!"]
...

有什么区别?

【问题讨论】:

    标签: docker docker-compose dockerfile


    【解决方案1】:

    docker-compose 文件中的command 参数覆盖了DockerFile 中的默认CMD

    【讨论】:

    • 替代还是补充?
    • 替换。一个容器只运行一个命令。
    猜你喜欢
    • 2014-02-28
    • 1970-01-01
    • 2010-09-14
    • 2015-08-09
    • 2018-05-14
    • 1970-01-01
    • 1970-01-01
    • 2020-05-25
    相关资源
    最近更新 更多