Various Docker-Compose related tips.
Installing latest binary release of Docker-Compose on Linux
One of the things I like about Docker-Compose is that it's a single binary that is easily distributable.
You can of course install Docker-Compose via your distribution's package manager, but I prefer to install and manage docker-compose manually as I've had a few previous issues (or newer features missing) caused by older versions available in the package manager.
The following script simply downloads, makes executable, and copies the latest Docker-Compose version to your user
#!/bin/bash VERSION=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep 'tag_name' | cut -d\" -f4) wget https://github.com/docker/compose/releases/download/$VERSION/docker-compose-Linux-x86_64 -O docker-compose mv docker-compose $HOME/.local/bin chmod +x $HOME/.local/bin/docker-compose
Updating all images and containers in Docker-Compose subfolders
Often I have several docker-compose files in various subfolders - e.g. parent/docker-compose-app1, parent/docker-compose-app2, parent/docker-compose-app3 etc. and want to update all docker images & containers at once.
The below script will parse each subfolder of a parent folder and pull the latest docker image and restart (if necessary) the associated container.
#!/bin/bash for d in $(ls -d */); do echo -e "\n==> pulling $d" cd $d; dc pull; echo -e "==> up $d" dc up -d; cd ..; done