Last active
June 21, 2018 02:32
-
-
Save ajibs/a3e92296cd8ff212c7c956ff6a6fd033 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}_" | |
fi | |
echo " ----- Project name prefix is: ${PROJECT_NAME} -----" | |
docker-compose -p ${PROJECT_NAME} up -d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment