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"

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay