Usage Of Docker Compose: A Step-By-Step Guide
Step 1: Firstly Create a docker compose file. Here I am using the below docker compose file with name Docker-compose.yml to explain the difference of docker compose commands. For practice take the following docker compose yaml file:
version: '3.1'
services:
mongo:
image: mongo:latest
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
mongo-express:
image: mongo-express:latest
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
ME_CONFIG_MONGODB_URL: mongodb://root:example@mongo:27017/
Step 2: Pull the docker images to local environment with the below docker compose command:
docker compose pull
Step 3: Validate and check errors in the docker compose file with this below command:
docker compose config
Step 4: Run the docker compose application with following command:
docker compose up
Step 5: After this you can access the application at <host-machine-ip>:8081 , Here default_user_name is admin and default password is pass.
Step 6: List down all the docker containers that are running.
docker compose ps
Step 7: See the logs of docker containers.
docker compose logs
Step 8: See the running processes within each service defined in a docker compose application .
docker compose top
Step 9: Restart all the docker containers
docker compose restart
Step 10: Stop the docker containers with the following commands.
docker compose stop
Step 11: Stop And remove the docker containers.
docker compose down
Docker Compose CLI Registry
Docker Compose is a powerful tool that is used to manage multi-container docker applications. Here in this guide, I will first discuss about Docker Compose CLI Registry. Then I will discuss the steps to set up the Docker Compose CLI Registry on an Ubuntu machine. After this, I will guide you through the important Docker Compose commands to manage multi-docker container applications. By the end, you will gain a profound understanding of Docker Compose and can use commands for effortless management of multi-container applications.