Common Docker Compose commands

Docker is fantastic tool to containerize a service and all it's dependencies. However, in practice rarely do you use a service by itself. Typically, you will have multiple services (or micro-services) collaborating to provide all the features of a customer facing application. 

Docker compose is a tool from Docker that allows you to quickly and reliably spin up multiple containers locally on your Mac, Windows or Linux desktop. It provides constructs to:

  1. Put all the related containers in one docker-compose file
  2. Ensure they spin up in certain order (E.g. a database should be up before an application calls it)
  3. Are part of same local network so they can send API requests to each other
Without Docker compose it would be quite a pain to do all the above yourself.

Here are some commands i use frequently when running docker compose: 

  1. Let's say you modified one of the dockerfile or the service code. You then run the below command to build a new image:
    • docker compose build <service_name>
  2. Once you build the image, then you will need to publish it to a public or private registry. 
    • docker push <image name from step 1>
  3. Now run below command to spin up ALL the services that are part of the docker compose file:
    • docker compose up -d
  4. Sometimes you need to recreate docker images of all the services and then start the respective containers:
    • docker-compose up -d --build --force-recreate
  5. To stop and restart specific docker services:
    • docker-compose stop <service_name>
    • docker-compose restart <service_name> 

Comments

Popular posts from this blog

Software Alerting maturity levels

Playwright - The Game Changer Test Automation Tool

New Habits for 2023