Docker create a mirror two ways to explain _docker

Source: Internet
Author: User
Tags docker run

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:

    Apt-get Install GCC


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:

    mkdir gcc
    cd gcc

Then we create a dockerfile file in the directory:

    Vim Dockerfile

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.