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"
Top comments (0)