Windows 2025
Sponsored Link

Docker : Access to Services on Container2024/12/16

 

If you'd like to access to services like HTTP or SSH which is running on Containers as a daemon, set like follows.

[1] For exmaple, run a container to use the container image which has IIS service like the example of here.
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\Administrator> docker images 
REPOSITORY                             TAG        IMAGE ID       CREATED         SIZE
srv.world/iis                          latest     88abadb6d8ac   2 minutes ago   5.26GB
mcr.microsoft.com/windows/servercore   ltsc2025   f9fb7d5c26c9   7 days ago      5.14GB

# map the port of Host and the port of Container with [-p xxx:xxx]
PS C:\Users\Administrator> docker run -t -d -p 8081:80 srv.world/iis cmd 
f7d4c2a9066dd2ec273a58b388393fd7c232239dd4fd9de8c955015a73975098

PS C:\Users\Administrator> docker ps 
CONTAINER ID   IMAGE           COMMAND   CREATED          STATUS          PORTS                  NAMES
f7d4c2a9066d   srv.world/iis   "cmd"     13 seconds ago   Up 11 seconds   0.0.0.0:8081->80/tcp   focused_kare

# create a test page
PS C:\Users\Administrator> docker exec f7d4c2a9066d powershell -c "Write-Output 'IIS on Docker Container' | Out-File -Encoding default C:\inetpub\wwwroot\index.html" 

# verify accesses
PS C:\Users\Administrator> curl.exe localhost:8081 
IIS on Docker Container
Matched Content