How to Execute Multiple Commands in Docker-Compose?

Better Stack Team
Updated on August 1, 2022

It is possible to define and run multiple commands in the docker-compose.yml file.

To execute multiple commands using Docker-Compose, structure the file in the following way:

      context: .
    command: >
      sh -c "command1 &&
             command2 &&

You can define multiple commands to be executed by enclosing them in the character and connecting them using && operator.

If you want to for example execute migration in then tart the server in Python Django app, you can do the following:

command: >
    bash -c "python migrate &&
                       python runserver"
Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →