Docker

How to Use Docker Compose on Windows

Docker compose is a Docker CLI tool utilized to configure, manage, and deploy microservices and multi-container applications. It uses a YAML file as a compose file to configure the services along with other settings. These services will start using “docker-compose up” command. This command executes each configured service in a separate container. Moreover, Docker compose CLI also provides us with different commands to manage the composing services.

This tutorial will demonstrate how to use Docker compose on Windows.

Prerequisites: Install Docker Compose

To install the Docker compose tool, first, install the Docker Desktop application for Windows on the system. This app contains built-in Docker CLI, Docker Compose CLI, Compose plugin, Docker Engine, and other essential components.

Note: For the installation of the Docker Desktop application, visit our associated article.

How to Use Docker Compose on Windows?

To use the Docker compose on Windows, first, create a Dockerfile that defines the instructions for containerizing the application. After that, configure the services in the compose file and fire up the containers using the “docker-compose up” command.

For the illustration, check out the given instructions.

Step 1: Create Dockerfile

First, create a Dockerfile that contains instructions to create the snapshot of the Docker container. For instance, we have dockerized the “index.html” file using the following instructions:

  • FROM” instruction defines the container’s base image.
  • COPY” adds or copies the source file to the container’s executable path.
  • ENTRYPOINT” defines the executables or defaults of the Docker container:
FROM nginx:latest

COPY index.html /usr/share/nginx/html/index.html

ENTRYPOINT ["nginx", "-g", "daemon off;"]

Step 2: Create Compose File

Create a compose file named “docker-compose.yml” file that includes the service configuration settings. For instance, we have configured the “web” and “web1” services in compose file using the following instructions:

  • web” service will containerize the HTML program, and the “web1” service will use the “nginx:latest” image in the container.
  • build” key defines the Dockerfile or build context to containerize the application. For instance, we use Dockerfile instructions.
  • ports” allocates the container’s exposed ports:
version: "3"

services:

web:

build: .

ports:

- 80:80

web1:

image: nginx:latest

Step 3: Fire up the Services

After that, build and fire up the services in separate containers by utilizing the “docker-compose up” command:

docker-compose up -d

For the verification, visit the allocated port of localhost. Here, we have successfully run the HTML service using Docker compose on Windows:

That’s all! We have demonstrated how to use Docker compose on Windows.

Conclusion

To use Docker compose on Windows, first, install the Docker Compose CLI by installing the Docker Desktop application on Windows. After that, create a Dockerfile to dockerize the application. Configure the application services in a compose file to run each service in a separate Docker container. After that, utilize the “docker-compose up” command to start the composing services. This write-up has illustrated how to utilize the Docker compose on Windows.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.