Sử dụng dockerfile và tạo docker image tự động.
ví dụ: tạo dockerfile để cài đặt IIS.
PS C:\Users\Administrator> mkdir docker-test
PS C:\Users\Administrator\docker-test> cd docker-test
PS C:\Users\Administrator\docker-test> $str_file = @"
FROM mcr.microsoft.com/windows/servercore:1809
MAINTAINER ServerWorld
RUN dism.exe /online /enable-feature /all /featurename:iis-webserver /NoRestart
RUN echo Dockerfile test example > C:\inetpub\wwwroot\index.html
EXPOSE 80
CMD [ "cmd" ]
"@
PS C:\Users\Administrator\docker-test> $str_file | Out-File Dockerfile -Encoding Default
# build image ⇒ docker build -t [image name]:[tag] .
PS C:\Users\Administrator\docker-test> docker build -t srv.world/iis-server:latest .
Sending build context to Docker daemon 2.048kB
Step 1/6 : FROM mcr.microsoft.com/windows/servercore:1809
---> 5c1f582f60a9
Step 2/6 : MAINTAINER ServerWorld
---> Running in 48d196707126
Removing intermediate container 48d196707126
---> e6345d98e44b
Step 3/6 : RUN dism.exe /online /enable-feature /all /featurename:iis-webserver /NoRestart
---> Running in 8435c833b7c6
.....
.....
Successfully built d0b43de1e6a4
Successfully tagged srv.world/iis-server:latest
PS C:\Users\Administrator\docker-test> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
srv.world/iis-server latest d0b43de1e6a4 About a minute ago 5.32GB
mcr.microsoft.com/windows/servercore 1809 5c1f582f60a9 12 days ago 5.12GB
# run Container on background
PS C:\Users\Administrator\docker-test> docker run -t -d -p 8081:80 srv.world/iis-server
ebd915020c61c0f0ed21b4a277ed14eb4e8eb1d863bfd7c42136ffcd1343a70f
PS C:\Users\Administrator\docker-test> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NA
MES
ebd915020c61 srv.world/iis-server "cmd" 9 seconds ago Up 8 seconds 0.0.0.0:8081->80/tcp nervous_hypatia
# verify accesses
PS C:\Users\Administrator\docker-test> curl.exe localhost:8081
Dockerfile test example