| by Arround The Web | No comments

Basic Docker Compose Commands

Docker compose is a well-liked, free, open-source command line utility of the Docker platform that is universally utilized to deploy or containerize multiple containers applications and other microservices. In Docker compose, each application service executes in a separate container. Moreover, Docker compose utility supports different commands to manage and execute these containers.

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:

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:

docker-compose -v

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:

docker-compose up

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:

docker-compose down

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:

docker-compose up -d

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:

docker-compose up -d --no-recreate

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:

docker-compose up --scale web1=2

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:

docker-compose ps -a

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:

docker-compose pull web2

Command 9: List Images

To list down the images created or pulled by Docker compose, use “docker-compose images” command:

docker-compose images

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:

docker-compose kill web1

Command 11: View Container Logs

Check the logs of Docker containers that are executing the compose services through the mentioned command:

docker-compose logs

Command 12: Pause Service

To pause any compose service for some duration or time, use “docker-compose pause <service-name>” command:

cker-compose pause web1

Command 13: Unpause Service

Similarly, to unpause the service in Docker compose use “docker-compose unpause <service-name>” command:

docker-compose unpause web1

Command 14: Stop Service

In order to stop any executing service, run the “docker-compose stop <service-name>” command:

docker-compose stop web

Command 15: Remove Service

Use “docker-compose rm” command to remove any stopped services in Docker compose:

docker-compose rm web

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.

Share Button

Source: linuxhint.com

Leave a Reply