Windows 2025
Sponsored Link

Docker : Docker Compose2024/12/16

 

To Install Docker Compose, it's easy to configure and run multiple containers as a Docker application.

[1] Install Docker Compose. Make sure the latest version on the site below.
⇒ https://github.com/docker/compose/releases
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\Administrator> Invoke-WebRequest "https://github.com/docker/compose/releases/download/v2.32.0/docker-compose-windows-x86_64.exe" -UseBasicParsing -OutFile 'C:\Windows\System32\docker-compose.exe' 

PS C:\Users\Administrator> docker-compose --version 
Docker Compose version v2.32.0
[2] For example, Configure an application that has IIS services with Docker Compose.
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

# create Dockerfile
PS C:\Users\Administrator> mkdir docker-file 
PS C:\Users\Administrator> cd docker-file 

PS C:\Users\Administrator\docker-file> $str_file = @"
FROM mcr.microsoft.com/windows/servercore:ltsc2025

SHELL ["powershell", "-command"]
RUN Install-WindowsFeature Web-Server
RUN Invoke-WebRequest -Uri https://dotnetbinaries.blob.core.windows.net/servicemonitor/2.0.1.10/ServiceMonitor.exe -OutFile C:\ServiceMonitor.exe

EXPOSE 80

ENTRYPOINT ["C:\\ServiceMonitor.exe", "w3svc"]
"@ 

PS C:\Users\Administrator\docker-file> $str_file | Out-File Dockerfile -Encoding Default 

# define application configration
PS C:\Users\Administrator\docker-file> $str_file2 = @"
services:
  web:
    build: .
    ports:
      - "80:80"
    volumes:
      - C:\iis:C:\inetpub\wwwroot
"@ 

PS C:\Users\Administrator\docker-file> $str_file2 | Out-File docker-compose.yml -Encoding Default 

PS C:\Users\Administrator\docker-file> mkdir C:\iis 

# buid and run
PS C:\Users\Administrator\docker-file> docker-compose up -d 
Sending build context to Docker daemon     432B
Step 1/7 : FROM mcr.microsoft.com/windows/servercore:ltsc2025
 ---> f9fb7d5c26c9
Step 2/7 : SHELL ["powershell", "-command"]
[+] Running 0/1
[+] Running 0/1 Building                          
 - Service web  Building                          
 ---> Removed intermediate container 65214e2180ce
[+] Running 0/1e6f
[+] Running 0/1 Building                          
 - Service web  Building                          

.....
.....

[+] Running 0/140e
[+] Running 0/1 Building                          
 - Service web  Building                          
 ---> Removed intermediate container b0035ab37f37
 ---> 9d2d11c741f2
[+] Running 3/3ilt 9d2d11c741f2
 ✓ Service web                  Built             
 ✓ Network docker-file_default  Created           
 ✓ Container docker-file-web-1  Started           

PS C:\Users\Administrator\docker-file> docker ps 
CONTAINER ID   IMAGE             COMMAND                   CREATED              STATUS              PORTS                NAMES
c8201674845f   docker-file-web   "C:\\ServiceMonitor.e…"   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp   docker-file-web-1

# create a test file
PS C:\Users\Administrator\docker-file> Write-Output "Docker Compose Test Page" | Out-File C:\iis\Default.htm -Encoding Default 

# verify accesses
PS C:\Users\Administrator\docker-file> curl.exe localhost 
Docker Compose Test Page
[3] Other basic operations of Docker Compose are follows.
PS C:\Users\Administrator\docker-file> docker-compose ps 
NAME                IMAGE             COMMAND                   SERVICE   CREATED         STATUS         PORTS
docker-file-web-1   docker-file-web   "C:\\ServiceMonitor.e…"   web       2 minutes ago   Up 2 minutes   0.0.0.0:80->80/tcp

# run any commands inside a container
# container name is just the one set in [docker-compose.yml]
PS C:\Users\Administrator\docker-file> docker-compose exec web powershell 

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\> hostname 
c8201674845f

PS C:\> exit 

# stop application and also shutdown all containers
PS C:\Users\Administrator\docker-file> docker-compose stop 
[+] Stopping 1/1
 ✓ Container docker-file-web-1  Stopped

# to start application again, run like follows
PS C:\Users\Administrator\docker-file> docker-compose up 
[+] Running 1/1
 ✓ Container docker-file-web-1  Recreated 
Attaching to web-1

# remove all containers in application
# if a container is running, it won't be removed
PS C:\Users\Administrator\docker-file> docker-compose rm 
? Going to remove docker-file-web-1 Yes
[+] Removing 1/0
 ✓ Container docker-file-web-1  Removed
Matched Content