Windows 2022
Sponsored Link

Docker : Access to Services on Container2022/01/21

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                          latest     f815baae1cc7   20 seconds ago   5.07GB   ltsc2022   11cbc9e36c7a   4 days ago       4.95GB

# 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 cmd 

PS C:\Users\Administrator> docker ps 
CONTAINER ID   IMAGE           COMMAND   CREATED          STATUS          PORTS                  NAMES
c001b1a67f82   "cmd"     36 seconds ago   Up 34 seconds>80/tcp   busy_greider

# create a test page
PS C:\Users\Administrator> docker exec c001b1a67f82 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