Skip to content

Instantly share code, notes, and snippets.

@ajibs
ajibs / dockerComposeProjectNameFix.sh
Last active June 21, 2018 02:32
Bash script that sets the project name based on the docker compose version. This helps to avoid inconsistent behaviour with project naming in different versions of docker compose while spinning up docker containers.
PROJECT_NAME="gameofthrones"
CURRENT_DOCKER_COMPOSE_VERSION=$( docker-compose -v | grep -o '[0-9]*[.][0-9]*[.][0-9]' | sed -e 's/[.]//g' )
BREAKING_DOCKER_COMPOSE_VERSION=1210
# Since docker compose version: '1.21.0', the network setup automatically adds a single '_' to the project_name,
# while version '1.20.0' and below replaces any extra ‘_’ at the end of the project_name with a single '_'.
# This assumes that at versions below '1.20.0' e.g. '1.9.0', no ‘_’ is added at the end of the project_name.
if [[ ${CURRENT_DOCKER_COMPOSE_VERSION} -lt ${BREAKING_DOCKER_COMPOSE_VERSION} ]]; then
PROJECT_NAME="${PROJECT_NAME}_"