How to Install Docker Compose on Windows Server 2016 / 2019 / 2022

How to Install Docker Compose on Windows Server 2016 / 2019 / 2022. In this tutorial we will introduce Docker with it’s main advantages then move onto installation phase on Windows server.

Imagine a situation where you want to use two containers in a single system. In such a case, building, running and connecting the container from separate Docker files can be very difficult. It will take a lot of your time and even affect your productivity. That is why you need to consider Docker Compose.

What Is Docker Compose?

A Docker tool used for defining and running multi container Docker applications. Every container running on this platform is isolated. However, they can interact with each other as and when needed.

Moreover, Docker Compose files are written in an easy scripting language called YAML. An XML based language whose acronym is Yet Another Markup Language. What makes this tool highly popular among users is its feature of providing access to activate all the services using a single command.

In a nutshell, instead of containing all the services in a huge container, Docker Compose splits them up into individually manageable containers. It proves to be highly advantageous both for building and deployment as you can manage all of them in distinct codebases.

You can use a Docker Compose in three processes:

  • Firstly to build component images using Docker Files, or get them from the libraries.
  • Secondly to determine every component service in the “docker-compose.yml” files.
  • Lastly to run them together via “docker-compose” CLI.

Docker Compose Features

Docker Compose constitutes the following features:

  • Supporting Environment Variables -here the Docker Compose enables you to customize containers based on different environments or users by adding variables in the Docker Compose files. This way, you tend to get more flexibility while setting up containers with Compose. Interestingly you can use this feature for almost anything from securely providing passwords to specifying a software version.
  • Reusing Existing Containers – where Docker Compose recreates containers that have changed since the last run. If it notices no changes, it re uses the existing container. It relies on the ability of the software to cache container configuration, thereby allowing you to set up your services faster.
  • Volume Data Preservation – with Docker Compose it saves data used by the services. You do not have to worry about losing data created in containers. If you have containers from the previous run, it will find them and copy their volumes to the new run.

Advantages Of Docker Compose

Some of the crucial benefits of Docker Compose are as follows:

  • Immediate And Straightforward Configurations – Since Docker Compose uses YAML scripts and environment variables, configuring and modifying application services is very effortless.
  • Provides Portability And CI/CD Support – All the services are defined inside of the Docker Compose files, making it effortless for developers to access and share the entire configuration. If they pull the YAML files and source code, an environment can be launched in just a matter of minutes. This way, setting and enabling CI/CD pipelines is very easy.
  • Internal Communication Security – With the help of Docker Compose, you can create a network for all the services to share. It adds an extra security layer for the app as the services cannot be accessed externally.
  • Using Resources Efficiently -by using Docker Compose, you can host multiple environments on one host. When you run everything on a single piece of hardware, you save a lot of resources. This way, it can cache configuration and re use existing containers contributing to resource efficiency.

Follow this post to show you how to install Docker Compose on Windows Server 2016, 2019 and 2022.

Install Docker Compose on Windows Server 2016, 2019 and 2022

Prerequisites

  • A user with administrative privileges.
  • Minimum 4 GB of RAM with 2 Cores CPU.

Verify Docker Installation

Before installing Docker Compose, you will need to make sure Docker is installed on your Windows server. To verify the Docker installation, open your Windows command prompt and run the following command:

				
					docker.exe version
				
			

If Docker is installed on your system, you will get the following information:

				
					Client: Docker Engine - Enterprise
 Version:           19.03.2
 API version:       1.40
 Go version:        go1.12.8
 Git commit:        c92ab06ed9
 Built:             09/03/2019 16:38:11
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Enterprise
 Engine:
  Version:          19.03.2
  API version:      1.40 (minimum version 1.24)
  Go version:       go1.12.8
  Git commit:       c92ab06ed9
  Built:            09/03/2019 16:35:47
  OS/Arch:          windows/amd64
  Experimental:     false

				
			

Install Docker Compose

Before installing Docker Compose, you will need to enable TLS12 in PowerShell to download the Docker Compose binary from the Git Hub.

First step is to open the PowerShell as an administrator user. Run the following command to enable the Tls12:

				
					[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
				
			

Second step is to change the directory to the Docker directory with the following command:

				
					cd C:\Program Files\Docker>
				
			

Next step is to download the latest version of Docker Compose binary from the Git Hub with the following command:

				
					Invoke-WebRequest "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Windows-x86_64.exe" -UseBasicParsing -OutFile docker-compose.exe
				
			

Once the Docker Compose is downloaded, you can verify the Docker Compose version with the following command:

				
					docker-compose.exe version
				
			

You will get the Docker Compose version in the following output:

				
					docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1g  21 Apr 2020
				
			

Docker Compose Help

If you are new to Docker Compose and don’t know all option to run it, then use this command to see the list of all options:

				
					docker-compose.exe --help
				
			

You will get the following list:

				
					Commands:
  build              Build or rebuild services
  config             Validate and view the Compose file
  create             Create services
  down               Stop and remove resources
  events             Receive real time events from containers
  exec               Execute a command in a running container
  help               Get help on a command
  images             List images
  kill               Kill containers
  logs               View output from containers
  pause              Pause services
  port               Print the public port for a port binding
  ps                 List containers
  pull               Pull service images
  push               Push service images
  restart            Restart services
  rm                 Remove stopped containers
  run                Run a one-off command
  scale              Set number of containers for a service
  start              Start services
  stop               Stop services
  top                Display the running processes
  unpause            Unpause services
  up                 Create and start containers
  version            Show version information and quit

				
			

Create a Sample IIS Container with Docker Compose

To use Docker Compose, you will need to create a docker-compose.yml file where you can define your all applications, interconnect all with each other and run them using a single command.

Let’s create a docker-compose.yml file to launch a simple IIS container. To do so, open your Notepad++ editor and add the following configurations:

				
					version: "2.1"
services:
  iis-demo:
    build: .
    image: "iis-demo:1.0"
    ports:
    - "80"
    networks:
      nat:
        ipv4_address: 172.24.128.2
    volumes:
    - "c:/temp:c:/inetpub/logs/LogFiles"
    environment:
    - "env1=LIVE1"
    - "env2=LIVE2"
    - "HOSTS=1.2.3.4:TEST.COM"
networks:
  nat:
    external: true
				
			

Save the file with name docker-compose.yml.

Next step is to create a Docker file using the Notepad++ editor using the following content:

				
					FROM microsoft/iis

# install ASP.NET 4.5
RUN dism /online /enable-feature /all /featurename:IIS-ASPNET45 /NoRestart

# enable windows eventlog
RUN powershell.exe -command Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\WMI\Autologger\EventLog-Application Start 1

# set IIS log fields
RUN /windows/system32/inetsrv/appcmd.exe set config /section:system.applicationHost/sites /siteDefaults.logFile.logExtFileFlags:"Date, Time, ClientIP, UserName, SiteName, ServerIP, Method, UriStem, UriQuery, HttpStatus, Win32Status, TimeTaken, ServerPort, UserAgent, Referer, HttpSubStatus"  /commit:apphost

# deploy webapp
COPY publish /inetpub/wwwroot/iis-demo
RUN /windows/system32/inetsrv/appcmd.exe add app /site.name:"Default Web Site" /path:"/iis-demo" /physicalPath:"c:\inetpub\wwwroot\iis-demo"

# set entrypoint script
ADD SetHostsAndStartMonitoring.cmd \SetHostsAndStartMonitoring.cmd
ENTRYPOINT ["C:\\SetHostsAndStartMonitoring.cmd"]

# declare volumes
VOLUME ["c:/inetpub/logs/LogFiles"]

				
			

Save the file with name Dockerfile.

Following step is to open your PowerShell as a administrator and change the directory to the directory where your docker-compose.yml and Dockerfile are saved.

Now run the following command to download IIS image and start the container:

				
					docker-compose.exe up -d
				
			

Once the IIS container is started, you can verify the running container using the following command:

				
					docker-compose.exe ps 
				
			

To check the container logs, run the following command:

				
					docker-compose.exe logs
				
			

If you want to stop the IIS container, run the following command:

				
					docker-compose.exe down
				
			

That is great! We have learned How to Install Docker Compose on Windows Server 2016 / 2019 / 2022. it is time to summarize.

How to install Docker Compose on Windows Server 2016, 2019 and 2022 Conclusion

In this post, we explained how to install Docker Compose on Windows server 2016, 2019 and 2022. We also explained how to create a Docker file and docker-compose.yml file to launch the IIS demo container. I hope you can now easily launch your container using Docker Compose on Windows machine.

Docker Compose is very useful tool that make it easier orchestrate multiple containers to work together, especially in the case where you need to orchestrate more complex applications with multiple services. Docker compose also helps developers to automate the deployment of their code.

Please take a look at our Docker content here

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x