Docker multiple entrypoints

后端 未结 9 858
情深已故
情深已故 2020-12-13 00:08

Say I have the following Dockerfile:

FROM ubuntu

RUN apt-get update
RUN apt-get install -y apache2
RUN apt-get install -y mongod #pretend this exists

EXPOS         


        
相关标签:
9条回答
  • 2020-12-13 00:34

    I was not able to get the usage of && to work. I was able to solve this as described here: https://stackoverflow.com/a/19872810/2971199

    So in your case you could do:

    RUN echo "/usr/sbin/apache2" >> /etc/bash.bashrc
    RUN echo "/path/to/mongodb" >> /etc/bash.bashrc
    ENTRYPOINT ["/bin/bash"]
    

    You may need/want to edit your start commands.

    Be careful if you run your Dockerfile more than once, you probably don't want multiple copies of commands appended to your bash.bashrc file. You could use grep and an if statement to make your RUN command idempotent.

    0 讨论(0)
  • 2020-12-13 00:34

    There is an answer in docker docs: https://docs.docker.com/config/containers/multi-service_container/

    But in short

    If you need to run more than one service within a container, you can accomplish this in a few different ways.

    The first one is to run script which mange your process.

    The second one is to use process manager like supervisord

    0 讨论(0)
  • 2020-12-13 00:37

    You can't specify multiple entry points in a Dockerfile. To run multiple servers in the same docker container you must use a command that will be able to launch your servers. Supervisord has already been cited but I could also recommend multirun, a project of mine which is a lighter alternative.

    0 讨论(0)
提交回复
热议问题