Skip to content

Docker cheat sheet

Matias Tamsi edited this page Aug 22, 2021 · 15 revisions

We recommend to consider taking the course DevOps with Docker.

Installation

Install Docker Engine and Docker Compose according to the instructions.

Commands

Here are useful commands gathered that are essential when working with the project.

See that docker and docker-compose might require sudo rights. Luckily this isn't the case in the ohtup-staging but propably on your own machine. One possible solution is in here.

Most common ones while developing

Run the program:

docker-compose up

Run the program taking consern possible modifications.

docker-compose up --build

Shut down the program:

docker-compose down

Run the unit tests:

docker-compose run qleader-web py.test

The code coverage can be generated by:

docker-compose run qleader-web coverage run -m pytest

Saving the coverage results can be done like this:

docker-compose run qleader-web coverage <option> (e.g. "xml" / "json" / "html" ... more options with "--help")

Listing the containers ('a' indicates that show even stopped ones):

docker container ls -a

Start with a clean sheet example

Here are the commands in the right order to be done in the staging, if there are changes that require more than Watchtower's restarting actions:

  1. Stopping the project (in the project folder with the docker-compose.yml -file):
docker-compose down
  1. Listing running containers (perhaps want to see what's the names of the containers):
docker container ls

To see all the containers, even the stopped ones, add the flag -a.

  1. Removing container (removing your project's old containers might be needed when creating new ones):
docker container rm qleader-db  # Here is an example so replace the container name "qleader-db" with correct one!
  • See that the container is stopped before trying to remove it. For this there are more options like stop and kill (or docker-compose down, if you are in the project folder) depending on the situation.
  1. Building project (in the beginning or if there are some bigger changes, for example, changes in the database)
docker-compose up --build -d
  1. Restarting (in the folder /nginx):
docker-compose restart

Can be also done in the _/qleader if needed.

Repositories

Clone this wiki locally