Docker mirroring and Container commands

Source: Internet
Author: User
Tags docker ps docker run

Docker is an open-source engine that makes it easy to create a lightweight, portable, self-sufficient container for any application. Developers who compile tests on notebooks can be deployed in batches in a production environment, including VMS (virtual machines), bare metal, OpenStack clusters, and other underlying application platforms.
Docker is typically used for the following scenarios:
Automated packaging and publishing of Web applications;
Automated testing and continuous integration, release;
Deploy and tune databases or other back-end applications in a service-oriented environment;

Build your own PAAs environment by compiling from scratch or by extending your existing OpenShift or cloud foundry platform.

First, mirror-related commands

1. Get the image

[Plain]View PlainCopy 
    1. sudo docker pull ubuntu:12.04

2. List local Mirrors

[Plain]View PlainCopy 
    1. sudo docker images

In the listing information, you can see several field information

from which warehouse, such as Ubuntu
Mirrored tags, such as 14.04
Its ID number (unique)
Creation time
Mirror size
Where the image ID uniquely identifies the mirror, notice that ubuntu:14.04 and ubuntu:trusty have the same mirror ID, which means they are actually the same mirror.
Tag information is used to mark different images from the same warehouse. For example, there are multiple images in the Ubuntu repository, which can be differentiated by TAG information, such as 10.04, 12.04, 12.10, 13.04, 14.04, and so on. For example, the following command specifies that a container be started using a mirrored ubuntu:14.04.

3. Create image

Method One:

[Plain]View PlainCopy 
    1. Docker commit

Method Two:

[Plain]View PlainCopy 
    1. DockerFile

4. Remove the local mirror

[Plain]View PlainCopy  
    1. You can use the Docker RMI command. Note the Docker RM command removes the container.

* Note: Use docker rm to delete all containers that depend on this image before deleting the image.

5, deposit and load photographed image
To save a mirror
If you want to export the image to a local file, you can use the Docker Save command.

6, Load photographed image

You can use Docker load to import from an exported local file to a local mirror library, for example

[Plain]View PlainCopy  
    1. sudo docker load--input Ubuntu_14.04.tar

Or

[Plain]View PlainCopy 
    1. $ sudo docker load < Ubuntu_14.04.tar


This imports the image and its associated metadata information (including tags, and so on).

Ii. container-related commands

1. Start the container

There are two ways to start a container, one is to create a new container based on the mirror and start, and the other is to restart the container in the terminating state (stopped).

Because Docker containers are too lightweight, many times users are deleting and creating new containers at any time. The required commands are primarily Docker run.
(1) New and started

The following command launches a bash terminal that allows the user to interact.

[Plain]View PlainCopy 
    1. sudo docker run-t-i Training/sinatra/bin/bash

Where the-t option allows Docker to assign a pseudo-terminal (Pseudo-tty) and bind to the container's standard input,-I keeps the container's standard input open. can also be combined to write

[Plain]View PlainCopy 
    1. sudo docker run-ti Ubuntu:14.04/bin/bash

Visible, only the specified bash app is running in the container. This feature makes Docker highly utilized for resources and is a genuine lightweight virtualization. If you don't add-t-i, you exit the container after execution. For example, the following command outputs a "Hello world" and then terminates the container.

[Plain]View PlainCopy 
    1. sudo docker run Ubuntu:14.04/bin/echo ' Hello world '


This is almost indistinguishable from the/bin/echo ' Hello World ', which is directly executed locally.

[Plain]View PlainCopy 

In interactive mode, users can enter commands through the terminal they create, such as

What if you just want the container to run in the background? Let's look at the following!

(2) when the daemon is running more, you need to let the Docker container run in the Daemon (daemonized) in the background. At this point, you can do so by adding the-D parameter. For example, the following command runs the container in the background.

When the container starts, it returns a unique ID, or you can view the container information through the Docker PS command.

Then use

[Plain]View PlainCopy  
    1. Docker Attach container Name

You can enter the container interface
The container name can be obtained by

[Plain]View PlainCopy 
    1. Docker Ps-a

If you enter the above:

Then enter:

When you use Docker run to create a container, the standard operations that Docker runs in the background include:
Checks if there is a specified image locally and does not exist to download from the public repository
Create and start a container with mirroring
Assign a file system and mount a layer of read-write layers outside the mirrored layer
Bridging a virtual interface into a container from the bridge interface configured by the host host
Configure an IP address from the address pool to the container
Executing user-specified applications
Container is terminated when execution is complete

(3) Start the termination of the container

The Docker start + container ID, command, can be used to launch a terminated container directly.

First find the ID of the container to start

[Plain]View PlainCopy 
    1. Docker Ps-a

Exited is the end of the show. Then use

[Plain]View PlainCopy 
    1. Docker start b3f9d3239bed

I started up two new containers in the way I was running on the table.

This is done in the background, how do you get into the container again? You can use Docker Attact + container name

First get the name of the container that is running through Docker ps-a, and then

[Plain]View PlainCopy 
    1. Docker Attach Goofy_mclean

As follows:

The core of the container is the application that is executed, and the resources required are required for the application to run. In addition, there are no other resources. You can use PS or top in a pseudo terminal to view process information.

(4) Exit container but keep running

By default, if you use ctrl-d to exit container, then container will stop, press Ctrl-p ctrl-q to exit to the host, and keep container still running. And then you go in and use Docker attach.

2. Stop container

Enter Exit or Ctrl+d

3. Get container information

To get the output information for a container, you can use the Docker logs command.

[Plain]View PlainCopy 
    1. Docker logs container name

4. Install a new program in the container

The next thing we do is to install a simple program (ping) inside the container. The tutorial image we downloaded earlier is based on Ubuntu, so you can use the Ubuntu apt-get command to install the ping program: Apt-get install-y Ping.
Note: After the apt-get command is executed, the container stops, but changes to the container are not lost.

5, save the changes to the container
When you make a change to a container (by running a command in the container), you can save the changes to the container so that the container can be run the next time you save the latest state. The process of saving state in Docker is called committing, which saves the difference between the old and new States, thus producing a new version. Or when it's over, we use Exit to exit, and now our container has been changed by us, using the Docker commit command to submit the updated copy.

Get the modified container ID first

Saving the container is actually saving it as a new image.

Where-M to specify the description of the submission, as we use the version Control tool;-A can specify updated user information, followed by the ID of the container used to create the mirror, and finally specify the warehouse name and tag information for the target image. The ID information for this image is returned when the creation is successful.

Use Docker images to view the newly created image.


After that, you can use the new mirror to start the container

6. Delete Container

You can use Docker RM to delete a container that is in a signaled state. For example


If you want to delete a running container, you can add the-f parameter. Docker sends a SIGKILL signal to the container.

7. Check the container in operation

Use the Docker PS command to see a list of all the containers that are running, and with the Docker inspect command we can view more detailed information about a particular container. Find the ID of a running container, and then use the Docker Inspect command to view the container's information. You can use the previous part of the mirror ID, which does not require a full ID.

Note:

Delete Command Summary

Docker images often fills the hard disk space unconsciously, in order to clean up the redundant image, the following methods can be used:

1. Enter root permissions

sudo su

2. Stop all container so that you can delete the images:

Docker stop $ (Docker ps-a-Q)

If you want to delete all container, add one more command:

Docker RM $ (Docker ps-a-Q)

3. See what images is currently

Docker images

4. Delete the images, by the ID of the image to specify who to delete

Docker RMI <image id>

If you want to delete untagged images, which is the image with ID <None>, you can use

Docker RMI $ (Docker images | grep "^<none>" | awk "{print $}")

To delete all of the image,

Docker RMI $ (Docker images-q)

http://blog.csdn.net/evankaka/article/details/49866265

Docker mirroring and Container commands (GO)

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.