Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 909
radicaled Avatar asked Jan 10 '19 02:01

radicaled


People also ask

Can we have multiple ENTRYPOINT in docker?

According to the documentation however, there must be only one ENTRYPOINT in a Dockerfile.

Can docker have multiple commands?

There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect. If CMD is used to provide default arguments for the ENTRYPOINT instruction, both the CMD and ENTRYPOINT instructions should be specified with the JSON array format.

How do I run multiple commands in Dockerfile?

Run Multiple Commands With Dockerfilethe semicolon (;) operator. the ambersand (&) operator. the AND (&&) operator. the OR (||) operator.

Can we use CMD and ENTRYPOINT together?

Example of using CMD and ENTRYPOINT togetherIf both ENTRYPOINT and CMD are present, what is written in CMD is executed as an option of the command written in ENTRYPOINT. If an argument is added at the time of docker run , the contents of CMD will be overwritten and the ENTRYPOINT command will be executed.


1 Answers

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

like image 183
Truong Dang Avatar answered Sep 29 '22 22:09

Truong Dang