DEV Community

@kon_yu
@kon_yu

Posted on

2 2

How to run multiple bash commands in CMD and docker-compose.yml of Dockerfile

When executing a command with CMD in Dockerfile or command in docker-compose.yml file, the
There is only one command that can be executed.

In this case, it is also possible to execute multiple commands by executing a shell script

A simpler way to execute multiple commands is to use

bash -c "Command string"

You only need to call it with bash -c for

It seems to say bash -c "ls -l && ls" in the console, so you might want to experiment.

Specifically, we will introduce an example of running elasticsearch on 9200 and 9250 ports.

Dockerfile

CMD bash -c "elasticsearch -d && elasticsearch --http.port=9250"

docker-compose.yml

command: bash -c "elasticsearch -d && elasticsearch --http.port=9250"

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay