I just started using docker. I create an image using docker file. How can I create a new image from that existing image?
You can create a new image by using docker command $docker build -f docker_filename . , It will first read the Dockerfile where the instructions are written and automatically build the image. The instruction in the Dockerfile contains the necessary commands to assemble an image. Once, the image is build, it will be assigned an image id. The image can be pushed to the docker registry hub. For this, the user must create an account in the docker registry hub.
An example of Dockerfile looks like this,
FROM docker/whalesay:latest RUN apt-get -y update && apt-get install -y fortunes CMD /usr/games/fortune -a | cowsay
Here, the first instruction tells the new image will be using docker/whalesay:latest image. The second instruction will run the two commands. And the third instruction tells that when the environment is set up "fortune -a" command should run.
Let's say you have a container bd91ca3ca3c8
running, and you want to create a new image after you made changes in the container. Generating another image will allow you to preserve your changes.
In that case you can run:
docker commit -p -a "author_here" -m "your_message" bd91ca3ca3c8 name_of_new_image
-p
pauses the container while commit command is building the new image.
-a
allows you to supply author information of the new image.
-m
allows you to add a comment just as in the Git.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With