radicaled
radicaled

Reputation: 2689

Multiple commands on docker ENTRYPOINT

I'm trying to build a custom tcserver docker image. But I'm having some problems starting the webserver and the tomcat.
As far as I understand I should use ENTRYPOINT to run the commands I want.
The question is, is it possible to run multiple commands with ENTRYPOINT?
Or should I create a small bash script to start all?

Basically what I would like to do is:

ENTRYPOINT /opt/pivotal/webserver/instance1/bin/httpdctl start && /opt/pivotal/webserver/instance2/bin/httpdctl start && /opt/pivotal/pivotal-tc-server-standard/standard-4.0.1.RELEASE/tcserver start instance1 -i /opt/pivotal/pivotal-tc-server-standard && /opt/pivotal/pivotal-tc-server-standard/standard-4.0.1.RELEASE/tcserver start instance2 -i /opt/pivotal/pivotal-tc-server-standard

But I don't know if that is a good practice or if that would even work.

Upvotes: 98

Views: 168834

Answers (4)

AlexeyP0708
AlexeyP0708

Reputation: 432

I personally encountered a problem where I needed to preserve the behavior of the parent image. My solution Example : Dockerfile (PARENT)

RUN ...
RUN ...
COPY ./entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
CMD ["default_param1"]

Dockerfile (CHILD)

RUN mv /entrypoint.sh /parent-entrypoint.sh
COPY ./entrypoint.sh /

#Optional. If the entry point is through a different script name
#ENTRYPOINT ["/entrypoint.sh"] 

#Indicate if the entry point has changed
#CMD ["default_param1"] 

/entrypoint.sh (child)

#!/bin/sh
/runMyscript.sh ; /parent-entrypoint.sh $@

Upvotes: 2

Truong Dang
Truong Dang

Reputation: 3427

In case you want to run many commands at entrypoint, the best idea is to create a bash file. For example commands.sh like this

#!/bin/bash
mkdir /root/.ssh
echo "Something"
cd tmp
ls
...

And then, in your DockerFile, set entrypoint to commands.sh file (that execute and run all your commands inside)

COPY commands.sh /scripts/commands.sh
RUN ["chmod", "+x", "/scripts/commands.sh"]
ENTRYPOINT ["/scripts/commands.sh"]

After that, each time you start your container, commands.sh will be execute and run all commands that you need. You can take a look here https://github.com/dangminhtruong/drone-chatwork

Upvotes: 112

Latif
Latif

Reputation: 1081

You can use something like this:

ENTRYPOINT ["/bin/sh", "-c" , "<command A> && <command B> && <command C>"]

Upvotes: 98

Aminadav Glickshtein
Aminadav Glickshtein

Reputation: 24630

You can use npm concurrently package.

For e.g.

ENTRYPOINT ["npx","concurrently","command1","command2"]

It will run them in parallel.

Upvotes: -15

Related Questions