Windows 2022
Sponsored Link

Docker : Docker Compose2022/01/25

 
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.2.3/docker-compose-Windows-x86_64.exe" -UseBasicParsing -OutFile $Env:ProgramFiles\docker\docker-compose.exe 

PS C:\Users\Administrator> docker-compose --version 
Docker Compose version v2.2.3
[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:ltsc2022

SHELL ["powershell", "-command"]
RUN Install-WindowsFeature Web-Server
RUN Invoke-WebRequest -Uri https://dotnetbinaries.blob.core.windows.net/servicemonitor/2.0.1.6/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 = @"
version: '3'
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     513B
Step 1/6 : FROM mcr.microsoft.com/windows/servercore:ltsc2022
 ---> 11cbc9e36c7a
Step 2/6 : SHELL ["powershell", "-command"]
 ---> Running in e70646a28478
Removing intermediate container e70646a28478
 ---> 9e1231e7ae71
Step 3/6 : RUN Install-WindowsFeature Web-Server
 ---> Running in d7c2c18180cb

.....
.....

Step 6/6 : ENTRYPOINT ["C:\\ServiceMonitor.exe", "w3svc"]
 ---> Running in b7ab30b05ce9
Removing intermediate container b7ab30b05ce9
 ---> db13c58d6184
Successfully built db13c58d6184
Successfully tagged docker-file_web:latest
[+] Running 1/1
 - Container docker-file-web-1  Started

PS C:\Users\Administrator\docker-file> docker ps 
CONTAINER ID   IMAGE              COMMAND                   CREATED          STATUS          PORTS                NAMES
71bdab92e0d5   docker-file_web   "C:\\ServiceMonitor.e…"   19 seconds ago   Up 17 seconds   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                 COMMAND                   SERVICE             STATUS              PORTS
docker-file-web-1   "C:\\ServiceMonitor.e…"   web                 running             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 
71bdab92e0d5

PS C:\> exit 

# stop application and also shutdown all containers
PS C:\Users\Administrator\docker-file> docker-compose stop 
[+] Running 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/0
 - Container docker-file-web-1  Created      0.0s
Attaching to docker-file-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
[+] Running 1/0ve docker-file-web-1 (y/N) y
 - Container docker-file-web-1  Removed
Matched Content