【Docker】Dockerfile 最佳实践-CMD
参考教程:https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
环境
- virtual box 6.1
- centos 7.8
- docker 19.03
CMD
The CMD
instruction should be used to run the software contained in your image, along with any arguments. CMD
should almost always be used in the form of CMD ["executable", "param1", "param2"…]
. Thus, if the image is for a service, such as Apache and Rails, you would run something like CMD ["apache2","-DFOREGROUND"]
. Indeed, this form of the instruction is recommended for any service-based image.
应该使用 CMD
指令来运行镜像中包含的软件以及所有参数。CMD
几乎应始终以 CMD ["executable", "param1", "param2"…]
的形式使用。因此,如果镜像用于服务,例如 Apache 和 Rails,则将运行诸如 CMD ["apache2","-DFOREGROUND"]
之类的内容。实际上,建议将这种形式的指令用于任何基于服务的镜像。
In most other cases, CMD
should be given an interactive shell, such as bash, python and perl. For example, CMD ["perl", "-de0"]
, CMD ["python"]
, or CMD ["php", "-a"]
. Using this form means that when you execute something like docker run -it python
, you’ll get dropped into a usable shell, ready to go. CMD
should rarely be used in the manner of CMD ["param", "param"]
in conjunction with ENTRYPOINT
, unless you and your expected users are already quite familiar with how ENTRYPOINT
works.
在大多数其他情况下,应该给 CMD
一个交互式外壳,例如 bash,python 和 perl。例如,CMD ["perl", "-de0"]
,CMD ["python"]
或 CMD ["php", "-a"]
。使用此种格式意味着执行 docker run -it python
之类的操作时,您将进入可用的 shell 中,随时可以使用。除非您和您的预期用户已经非常熟悉 ENTRYPOINT
的工作原理,否则 CMD
很少以 CMD ["param", "param"]
的形式与 ENTRYPOINT
结合使用。
总结
介绍了 Dockerfile 的 CMD 指令的最佳实践。
相关文章
- Docker用Dockerfile定制镜像
- 什么是docker的存储驱动?有什么作用?
- Why does Docker need a Union File System
- 转转测试环境docker化实践
- Centos7 系统启动docker报错 inotify add watch failed
- Docker存出载入镜像
- docker swarm实践爆心肝总结全在这里,火速收藏!!!
- 转转测试环境docker化实践
- 基于Docker的开发模式驱动持续集成落地实施
- 基于Docker的mysql mha 的集群环境构建实践
- Docker技术入门与实战(第2版)2.4 推荐实践环境
- 通过Mesos、Docker和Go,使用300行代码创建一个分布式系统
- docker安装es集群
- Maven私服:Docker安装nexus3
- Docker - 容器的网络模式
- Docker面试相关内容--2022年总结
- 《Docker生产环境实践指南》——1.3 使用Docker的多种方式
- Docker 部署 Grafana
- Docker中安装Drone(基于Gitea)
- Docker基础学习总结
- 如何清理Docker占用的磁盘空间?
- Docker容器日志管理最佳实践
- 10 个优化技巧,减少 Docker 镜像大小
- docker 创建网络 failed to allocate gateway (): No address returned 解决办法
- Docker数据卷