docker-compose.yml中的"command"参数和Dockerfile中的CMD参数有什么区别?

What is the difference between the "command" parameter in the docker-compose.yml and the CMD parameter in the Dockerfile?

如您所知,在 Dockerfile 中,您可以通过 运行 和 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-compose 文件中的

command 参数正在覆盖 DockerFile.

中的默认 CMD