Docker Commands

Running a Docker Stack with Docker Compose

Open a terminal, go to the folder of your Docker stack, containing the docker-compose.yml file, and run:

docker-compose up -d

To run it with a different compose file than docker-compose.yml ('i.e. traefik.yml), run:

docker-compose -f traefik.yml up -d

Stop a Docker Stack with Docker Compose

Open a terminal, go to the folder of your Docker stack, containing the docker-compose.yml file, and run:

docker-compose stop

To run it with a different compose file than docker-compose.yml ('i.e. traefik.yml), run:

docker-compose -f traefik.yml stop

Remove a Docker Stack with Docker Compose

Open a terminal, go to the folder of your Docker stack, containing the docker-compose.yml file, and run:

docker-compose rm

To run it with a different compose file than docker-compose.yml ('i.e. traefik.yml), run:

docker-compose -f traefik.yml rm

Run a command in a running container with Docker Compose

Open a terminal, go to the folder of your Docker stack, containing the docker-compose.yml file, and run:

docker-compose exec [CONTAINER] [COMMAND]

As example, to execute the command ls -la, on the Container php, run:

docker-compose exec php ls -la

Mac OS X users must run docker-compose exec ... with user 82. e.g.:

docker-compose exec --user 82 php ls -la

Enter in a running container with Docker Compose

Open a terminal, go to the folder of your Docker stack, containing the docker-compose.yml file, and run:

docker-compose exec [CONTAINER] sh

As example, to enter on the Container php, run:

docker-compose exec php sh

Once in, you can run any commands without prefixing with docker exec ....

Run Composer in a running container with Docker Compose

Open a terminal, go to the folder of your Docker stack, containing the docker-compose.yml file, and run:

docker-compose exec php composer ...

As example, to execute composer install, run:

docker-compose exec composer install

Run Drush in a running container with Docker Compose

Open a terminal, go to the folder of your Docker stack, containing the docker-compose.yml file, and run:

docker-compose exec php drush ...

As example, to execute drush cr, run:

docker-compose exec drush cr

Run Drupal Console in a running container with Docker Compose

Open a terminal, go to the folder of your Docker stack, containing the docker-compose.yml file, and run:

docker-compose exec php drupal ...

As example, to execute drupal generate:module, run:

docker-compose exec drupal generate:module

Access Drupal Database in a running container with Docker Compose

Open a terminal, go to the folder of your Docker stack, containing the docker-compose.yml file, and run:

docker-compose exec php drush sql-cli

Import Drupal Database in a running container with Docker Compose

Copy the Database dump on your project folder.

Open a terminal, go to the folder of your Docker stack, containing the docker-compose.yml file, and run:

docker-compose exec php drush sql-cli < [database_dump_name].sql
replace [database_dump_name].sql with your file name, i.e. db_dump-20190927.sql.

Dump/Export Drupal Database in a running container with Docker Compose

Copy the Database dump on your project folder.

Open a terminal, go to the folder of your Docker stack, containing the docker-compose.yml file, and run:

docker-compose exec php drush sql-dump --result-file=../[database_dump_name].sql
replace [database_dump_name].sql with the name you want to assign it, i.e. db_dump-20190927.sql.

Docker Aliases

You can optimize your docker command line workflow using aliases to create shortcuts.

See Handy Docker Aliases.