Search notes:

docker commit

docker commit creates a new image from a modified container.
Create a new container:
C:\> docker run -it mcr.microsoft.com/windows/nanoserver:1809 cmd.exe
Inside the container, create a file:
C:\>date /t > date-time.txt

C:\>time /t >> date-time.txt

C:\>type date-time.txt
Fri 12/20/2019
02:05 PM

C:\> exit
In order to create an image, we first need to determine the container's id:
C:\> docker ps -a
> docker ps -a
CONTAINER ID        IMAGE                                       COMMAND                   CREATED             STATUS                      PORTS               NAMES
282465b50140        mcr.microsoft.com/windows/nanoserver:1809   "cmd.exe"                 31 minutes ago      Exited (0) 3 seconds ago                        fervent_nightingale
83926cacc71d        mcr.microsoft.com/windows/nanoserver:1809   "cmd.exe"                 About an hour ago   Exited (0) 31 minutes ago                       musing_morse
  …
Use docker commit to create a new image, named a_new_image. Note that image names need to be lowercase:
C:\> docker commit 282465b50140 a_new_image
sha256:a80b39c04ea8c61277418ce6561e6d479596eaa5862ea27cd74a2565b53b8d06
View the available images:
C:\> docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
a_new_image                            latest              a80b39c04ea8        35 seconds ago      253MB
hello-world                            latest              16464c76a19c        9 days ago          251MB
mcr.microsoft.com/windows/nanoserver   1809                c897e7c62e1e        3 weeks ago         251MB
  …
Run the newly created container:
C:\> docker run a_new_image cmd.exe /c type date-time.txt 
Fri 12/20/2019
02:05 PM

Links

Much of this page was inspired (even copied) from Get started: Run your first Windows container.

Index