Docker Create mirrors
The recent study of Docker knowledge, accidentally on the internet to see the two ways to create objects Docker very good, here record, may be able to help you.
We all know that in Docker we are containers based on mirroring, so how do we create mirrors? There are two ways to create a mirror, one is to use the Docker commit command, and the other is to use the Docker build command and the Dockerfile file. Here we are talking about creating a mirror that is based on an existing base mirror such as Ubuntu, instead of creating a completely new mirror from zero.
Here are two simple ways to do this.
The first type is created using Docker commit.
First we can run a container first:
sudo docker run-i-t Ubuntu/bin/bash
Then we can make modifications in this container, such as installing some software or setting up some environment:
Finally, we submit these modifications and create a mirror image:
sudo dockercommit 4aa578389 BUFFOON/GCC
Here 4aa578389 is the ID,BUFFOON/GCC of the modified container is the target mirror warehouse and mirror name. We can also use some parameters to augment more information at the time of the commit. Like what:
sudo dockercommit-m "A new image with GCC"-A "buffoon" 4aa578389 buf/gcc:mm
The-m option specifies the mirroring submission, the-a option marks the author's information, and the last: MM is the label.
We can sudo dockerimages BUFFOON/GCC to see if the newly created mirrors have been successful. To view the details of the mirror, you can sudo docker inspect buf/gcc:mm.
The second type is created using the Docker build command and the Dockerfile file.
First we create an empty directory as the build environment, the build context in Docker:
Then we create a dockerfile file in the directory:
To edit in a file:
#Version: 0.0.1 from
ubuntu:latest
maintainerbuffoon xxx@gmail.com
RUN apt-getinstall gcc
In this file, from must be the first instruction, specifying the underlying mirror; the maintainer instruction indicates some information about the author; run indicates the command to be executed when mirroring is run.
Then we can go into the build context and execute the creation:
CD gcc
sudo dockerbuild-t= "buffoon/gcc:v1". Pay attention to the last number.
-t Specifies the warehouse mirroring label, and the last point is to indicate that the dockerfile file is being searched from the current path.
Dockerfile in the instructions there are many, here is not one to introduce, the specific instructions please see: https://docs.docker.com/engine/reference/builder/
Thank you for reading, I hope to help you, thank you for your support for this site!