From the course: Certified Kubernetes Application Developer (CKAD) Cert Prep

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Creating images from running containers

Creating images from running containers

- As an alternative for using a Docker file, it's also possible to create images using Docker commit, that allows you to create an image from a running container. So the procedure is then that you run your container, you make all modifications that you want to make, and then you use Docker commit to commit them to an image. Here we have the procedure. Let me show you. So I'm going to use docker run --name customweb -it nginx sh, so that opens a shell on the nginx container. And I'm going to use touch /tmp/testfile. This Linux command creates a file with the name TMP test file, and then I'm using exit. And by using exit, I'm already closing the container because while starting it with docker run -it nginx sh, I replaced the default command with a shell. And now I'm using exit. Exit shuts down the shell. Next, I'm using docker commit customweb nginx:custom. And then I'm using docker images, and what do we see? We see that new image has been created with the name nginx and the tag…

Contents