I just started using docker. I create an image using docker file. How can I create a new image from that existing image?
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- What would prevent code running in a Docker contai
- How to reload apache in php-apache docker containe
In order to create a new image from an existing image all you have to do is to specify 'FROM' for e.g:
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,
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.
Docker commit: Creates a new image from a container’s changes.
Let's say you have a container
bd91ca3ca3c8
running, and you want to create an image after you made changes in the container. You may want to generate another image to preserve your changes etc.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.