Basic Docker Compose Commands
This blog will provide the basic Docker compose commands that you must know.
Basic Docker Compose Commands
Different commands and options are supported by “docker-compose” for managing and processing multiple container programs and applications. We have listed some basic and frequently used commands of Docker compose that Docker users must know:
- Check Docker Compose Version
- Create Containers and Start Services
- Stop Service and Remove Containers
- Run Service in Detached Mode
- Run Service Without Creating the Containers
- Scale Service
- List Services or Containers
- Pull Image
- List Images
- Kill Service
- View Container Logs
- Pause Service
- Unpause Service
- Stop Service
- Remove Service
Command 1: Check Docker Compose Version
In order to check the version of Docker compose tool installed in your system, utilize “docker-compose -v” command:
Here, you can see we are currently using Docker Compose version “v2.15.1”:
Command 2: Create Containers and Start Services
To start the services, configure in the “docker-compose.yml” file to containerize the multi-container program, utilize the “docker-compose up” command. This command will create the containers and start each service in a different container:
Command 3: Stop Service and Remove Containers
To down or stop the running services in the containers, simply use the “docker-compose down” command. This command will automatically stop and remove the containers:
Command 4: Run Service in Detached Mode
You can start the composing services as a backend service or in a detached mode, utilize the “-d” option along with “docker-compose up” command:
Command 5: Run Service Without Re-creating the Containers
Docker users can also avoid re-creating the containers while restarting the services in the containers. For this purpose, simply add the “–no-recreate” option along with the “docker-compose up” command:
Command 6: Scale Service
You can create the replica or copy of services specified in “docker-compose.yml” file in a different container using the “–scale” option with “service-name=number of replicas” value:
Here, you can see we have successfully run the copy of “web1” service in a separate container:
Command 7: List Services or Containers
To list down the composed services or containers, utilize the “docker-compose ps” command. The “-a” option is used to list all compose containers and services:
Command 8: Pull Image
In order to pull the image that is required in any specified service in compose file, use the provided command with the service name:
Command 9: List Images
To list down the images created or pulled by Docker compose, use “docker-compose images” command:
Command 10: Kill Service
In order to kill and remove the running service in Docker compose, utilize the “docker-compose kill” command along with service name:
Command 11: View Container Logs
Check the logs of Docker containers that are executing the compose services through the mentioned command:
Command 12: Pause Service
To pause any compose service for some duration or time, use “docker-compose pause <service-name>” command:
Command 13: Unpause Service
Similarly, to unpause the service in Docker compose use “docker-compose unpause <service-name>” command:
Command 14: Stop Service
In order to stop any executing service, run the “docker-compose stop <service-name>” command:
Command 15: Remove Service
Use “docker-compose rm” command to remove any stopped services in Docker compose:
We have demonstrated the basic Docker compose commands.
Conclusion
Docker compose tool is being used to process and manage the multiple containers apps and programs. The basic Docker compose commands that you must know are “docker-compose up/down”, “docker-compose start/stop”, “docker-compose pull”, “docker-compose pause/unpause”, “docker-compose rm”, and “docker-compose kill”. This article has described the basic Docker compose commands that you must know.
Source: linuxhint.com