Table of Contents
This repo contains the resources used during "How to Control Service Startup Order in Docker Compose" presentation at the Keyboards & Mice iQuest public event, which took place in Brașov on June 6th, 2018.
This presentation is based on this article, but while the latter shows a Java console application fetching data from a MySQL database, the former uses a .NET Core console application fetching data from a PostgreSQL database.
SlideShare: https://www.slideshare.net/satrapu/how-to-control-service-startup-order-in-docker-compose
- Docker
- Docker Compose
- Docker Engine API
- curl
- jq
- .NET Core
- Home
- Documentation
- Docker images
- Using .NET Core in Visual Studio Code
- PostgreSQL ADO.NET driver
- PostgreSQL
- Alpine Linux
- Symbolic links on Windows
- The Complete Guide to Creating Symbolic Links (aka Symlinks) on Windows
- Create a hard-link from /dotnet-core-with-docker/sources to /dotnet-core-with-docker/compose/service-healthy folder:
# PowerShell cd .\dotnet-core-with-docker\compose\service-healthy cmd /c mklink /J .\sources .\..\..\sources
- Clone this repo
git clone https://github.com/satrapu/iquest-keyboards-and-mice-brasov-2018.git
cd ./iquest-keyboards-and-mice-brasov-2018
-
Start services
- Using depends_on, condition and service_healthy:
# Windows - PowerShell console run as admin cd .\compose\service-healthy ` ;cmd /c mklink /J .\sources .\..\..\sources ` ;docker-compose down --rmi local ` ;docker-compose build ` ;docker-compose up app
# Linux - Bash cd ./compose/service-healthy \ && mkdir ./sources && cp ../../sources/* sources \ && docker-compose down --rmi local \ && docker-compose build \ && docker-compose up app
- Using Docker Engine API
# Windows - PowerShell console run as admin cd .\compose\docker-engine-api ` ;cmd /c mklink /J .\sources .\..\..\sources ` ;$Env:COMPOSE_CONVERT_WINDOWS_PATHS=1 ` ;docker-compose down --rmi local ` ;docker-compose build ` ;docker-compose up app
# Linux - Bash cd ./compose/docker-engine-api \ && mkdir ./sources && cp ../../sources/* sources \ && docker-compose down --rmi local \ && docker-compose build \ && docker-compose up app
- Using port checking++
# Windows - PowerShell console run as admin cd .\compose\port-checking++ ` ;cmd /c mklink /J .\sources .\..\..\sources ` ;docker-compose down --rmi local ` ;docker-compose build ` ;docker-compose up --exit-code-from check_db_connectivity check_db_connectivity ` ;if ($LASTEXITCODE -eq 0) { docker-compose up app } ` else { echo "ERROR: Failed to start service due to one of its dependencies!" }
# Linux - Bash cd ./compose/port-checking++ \ && mkdir ./sources && cp ../../sources/* sources \ && docker-compose down --rmi local \ && docker-compose build \ && docker-compose up --exit-code-from check_db_connectivity check_db_connectivity \ && if [ $? -eq 0 ]; then docker-compose up app; else echo 'ERROR: Failed to start service due to one of its dependencies!'; fi