Scripts to deploy Docker Compose

Tiempo de lectura: < 1 minuto

Reading time: < 1 minute

Today I bring you some scripts that can help us deploy our Docker Compose automatically. These scripts are programmed in Bash and can be used in Ubuntu (.sh)

Script to deploy Docker Compose in the background

#!/bin/bash
# -*- ENCODING: UTF-8 -*-

echo "Deploying Docker container"
echo "1. Closing container if it was open"
sudo docker-compose down
echo "2. Opening docker"
sudo docker-compose up -d

This small script first closes Docker Compose if it was open and then starts it again.

Script to restart Docker Compose (Cleans the containers and rebuilds them)

#!/bin/bash
# -*- ENCODING: UTF-8 -*-

echo "Deploying Docker container"
echo "Closing container if it was open"
sudo docker-compose down
echo "Deleting containers to restore"
sudo docker rm -f $(sudo docker ps -a -q)
echo "Deleting docker volumes"
sudo docker rmi $(sudo docker images -a -q)
echo "Opening docker"
sudo docker-compose up -d

This script deletes the volumes of Docker Compose and recreates them. This way, we can avoid leaving stored data that takes up space.

Leave a Comment