-
Notifications
You must be signed in to change notification settings - Fork 1
Makefile
In this project, the Makefile will have a simple but essential function: to ensure that all the Docker images are created correctly through Docker Compose, including all the necessary dependencies.
This will ensure that the environment is properly configured and ready for the project to run efficiently and consistently.
-
Basic Configuration for Makefile
-
Create the automation file
Makefilein the path described below via the terminal:mkdir -p rootInception/Makefile
-
Fill the
Makefileso that when it is run, it builds all the Docker images defined in the YAML file using thecompose buildcommand, as decribed below:all: build build: docker-compose build
-
Add to the
Makefilethe command to start the containers from the previously built images, using thecompose upcommand, as decribed below:all: build up build: docker-compose build up: docker-compose up -d
-
Add to the
Makefilea check to see if the directories for storing persistent volumes exist, and if they don't, create them automatically, as a prerequisite for the previous steps, as decribed below:all: build up data: @if [ ! -d "home/ivbatist/data/mariadb" ] && [ ! -d "home/ivbatist/data/wordpress;" ]; then \ mkdir -p home/ivbatist/data/mariadb && mkdir -p home/ivbatist/data/wordpress; fi build: data docker-compose build up: docker-compose up -d
👉🏼 After this step is completed, the remaining commands are optional and can be used as needed to suit your specific requirements.
👉🏼 Below is a short list of Docker Compose commands that can be added to the Makefile:
-
docker compose up <docker_image_name>: Runs the container from the specified image. -
docker compose build <docker_image_name>: Runs the docker-compose.yml and builds Docker images. -
docker compose up --build: Executes the build and up commands sequentially, building and starting all containers described in the docker-compose.yml file. -
docker stop <container_name>: Pauses the execution of the specified container. -
docker stop $(docker ps -aq): Pauses ALL running containers. -
docker-compose down: Pauses and removes existing containers and associated networks. -
docker rm <container_name>: Removes the paused container specified. -
docker rm $(docker ps -aq): Removes all containers. -
docker rmi -f <docker_image_name>: Removes the specified image. -
docker image prune -a: Removes all unused images. -
docker ps: Displays a list of running containers. -
docker ps -a: Displays a list of created containers, running or paused. -
docker images: Displays a list of created images so far. -
docker network ls: Displays a list of created networks so far. -
docker network rm <network_name>: Removes the specified network. -
docker network inspect <network_name>: Displays details about the network. -
docker network prune: Removes ALL obsolete/unused networks. -
docker exec -it <container_name> <command>: Executes the specified command within the running container without needing to access the container.
-
-