问题描述
我从 Dockerfile 构建了一个名为 centos+ssh 的基础镜像.在centos+ssh的Dockerfile中,我使用CMD运行ssh服务.
I have built a base image from Dockerfile named centos+ssh. In centos+ssh's Dockerfile, I use CMD to run ssh service.
然后我想构建一个镜像,运行另一个名为rabbitmq的服务,Dockerfile:
Then I want to build a image run other service named rabbitmq,the Dockerfile:
FROM centos+ssh
EXPOSE 22
EXPOSE 4149
CMD /opt/mq/sbin/rabbitmq-server start
启动rabbitmq容器,运行:
To start rabbitmq container,run:
docker run -d -p 222:22 -p 4149:4149 rabbitmq
但是ssh服务不起作用,感觉rabbitmq的Dockerfile CMD覆盖了centos的CMD.
but ssh service doesn't work, it sense rabbitmq's Dockerfile CMD override centos's CMD.
- CMD 如何在 docker 镜像中工作?
- 如果我想运行多个服务,怎么做?使用主管?
推荐答案
尽管 CMD 写在 Dockerfile 中,但它确实是运行时信息.就像 EXPOSE 一样,但与例如相反运行和添加.我的意思是,您可以稍后在扩展的 Dockerfile 中或在运行命令中简单地覆盖它,这就是您正在经历的.任何时候都只能有一个 CMD.
Even though CMD is written down in the Dockerfile, it really is runtime information. Just like EXPOSE, but contrary to e.g. RUN and ADD. By this, I mean that you can override it later, in an extending Dockerfile, or simple in your run command, which is what you are experiencing. At all times, there can be only one CMD.
如果你想运行多个服务,我确实会使用supervisor.您可以为每个服务制作一个主管配置文件,将它们添加到目录中,然后使用 supervisord -c/etc/supervisor
运行主管以指向加载所有服务和外观的主管配置文件喜欢
If you want to run multiple services, I indeed would use supervisor. You can make a supervisor configuration file for each service, ADD these in a directory, and run the supervisor with supervisord -c /etc/supervisor
to point to a supervisor configuration file which loads all your services and looks like
[supervisord]
nodaemon=true
[include]
files = /etc/supervisor/conf.d/*.conf
如果你想了解更多细节,我在这里写了一篇关于这个主题的博客:http://blog.trifork.com/2014/03/11/using-supervisor-with-docker-to-manage-processes-supporting-image-继承/
If you would like more details, I wrote a blog on this subject here: http://blog.trifork.com/2014/03/11/using-supervisor-with-docker-to-manage-processes-supporting-image-inheritance/
这篇关于为什么我不能多次使用 Docker CMD 来运行多个服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!