Quick startup with Docker Compose

Hey, I'm a postgraduate in Cyber Security with practical experience in Software Engineering and DevOps Operations. The top player on TryHackMe platform, multilingual speaker (Kazakh, Russian, English, Spanish, and Turkish), curios person, bookworm, geek, sports lover, and just a good guy to speak with!
Overview:
Docker Compose - is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services.
Installation:
- Download the Docker Compose version 1.23.2:
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - Apply executable permission:
sudo chmod +x /usr/local/bin/docker-compose - Test the installation:
docker-compose --version
Basic commands:
- To create a compose service and startup in the background (before that create
docker-compose.ymlfile):docker-compose up -d - To list the containers created by Docker compose use:
docker-compose ps - To specify compose file use
-fflag:docker-compose -f [filepath] up -d - To stop a service:
docker-compose stop - To start service:
docker-compose start - To restart a service:
docker-compose restart - To delete a service:
docker-compose down
Docker Compose file:
- By default the
docker-compose.ymlis used to create compose services. You can specify any other file with-fflag - There are four types of top level keys in Docker compose file:
versionservicesnetworksvolumes
- Docker compose file format (
version) is dependent on which version of Docker you are using - Example of
docker-compose.ymlfile which utilizes the Dockerfile. To specify usage of Dockerfile use:build: context::version: '3' services: my-service: # --> Name of the service build: # --> Specifies build context context: . # --> Path to the Dockerfile (both files in the same directory) args: - VERSION=v4.1 ports: - "8080:4000" environment: - ENV=development - If changes were made into Dockerfile, before starting up a compose service you need to build it again:
docker-compose build - To bypass using the cache layers from previous built images use
--no-cacheflag:docker-compose build --no-cache





