Docker five easy-to-use containers

Source: Internet
Author: User

Simply put, a container is a running instance of a mirror, and the difference is that it has an extra layer of writable files.

If you think of a virtual machine as a complete set of operating systems that simulate running (providing a run-state environment and other system environments) and applications running on it. Then Docker containers are one or a set of applications that are geographically run, and their required operating environment.

1.1 creating a docker container

New container You can use the docker create command to create a new container, for example:

[email protected] ~]# Docker create-it Centos:centos6/bin/bash

* where - t means that entering terminal -I indicates that the standard input of the container remains open.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6C/04/wKiom1U9rlKCOzdKAAEjsCM1C0A105.jpg "title=" Picture 1.png "alt=" Wkiom1u9rlkcozdkaaejscm1c0a105.jpg "/>

A newly created container with the Docker create command is in a stopped state and can be started by using the Docker start command

Docker start (ID)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6C/04/wKiom1U9rl7zI9hwAAFoWESkGX4874.jpg "title=" Picture 2.png "alt=" wkiom1u9rl7zi9hwaafoweskgx4874.jpg "/>

Create and start a container

There are two ways to start a container, one to create a new container based on a mirror, and another to restart the container in the state of the termination. The required commands are primarily Docker run, which is equivalent to performing the Docker create command first in the Docker restart Command

Docker Run-t-I Centos:centos6/bin/bash

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6C/00/wKioL1U9r82CfsBFAABlxcjsohg392.jpg "title=" Picture 3.png "alt=" wkiol1u9r82cfsbfaablxcjsohg392.jpg "/>

When you use Docker run to create and start a container,the standard operations that Docker runs in the background include:

1. Check if there is a specified image locally and download it from the public repository if it does not exist.

2. Create and start a container with the image.

3. Assign a file system and mount a layer of read-write layers outside of the mirrored layer

4. Bridge a virtual interface into a container from a host-configured Network Bridge interface.

5. Configure an IP address from the address pool to the container.

6. Execute the application that the user knows.

7. The container is terminated after execution is complete.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6C/04/wKiom1U9rn3QksflAAHf_pKJr-8826.jpg "title=" Picture 4.png "alt=" Wkiom1u9rn3qksflaahf_pkjr-8826.jpg "/>

Exit the container with exit or ctrl+d If the container exits, the container is closed and The service in the Docker start restart will not be turned on.

Guard State Run

More often, you need to let the Docker container run in the background as a daemon. Users can add the- d parameter by adding the

[email protected] ~]# Docker run-d centos:centos6/bin/bash-c "while True;do echo Hello World;sleep 1; Done

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6C/04/wKiom1U9rpDwLKqhAAI6muUIhiQ177.jpg "title=" Picture 5.png "alt=" wkiom1u9rpdwlkqhaai6muuihiq177.jpg "/>

to get the output information for a container, you can Docker logs command

Docker logs container ID

Terminate container

You can use Docker stop to terminate a running container .

[[email protected] ~]# Docker stop d130a7e46842


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6C/00/wKioL1U9sAfDNz5wAAFK3vtZarE917.jpg "title=" Picture 6.png "alt=" Wkiol1u9safdnz5waafk3vtzare917.jpg "/>

A container in the terminating state, which can be restarted via the Docker start command;

[[email protected] ~]# Docker start d130a7e46842

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6C/00/wKioL1U9sCCin2XVAAEFNTyvlaM956.jpg "title=" Picture 7.png "alt=" Wkiol1u9sccin2xvaaefntyvlam956.jpg "/>

You can also use The Docker restart command terminates a run-state container and then restarts it

[email protected] ~]# Docker restart d130a7e46842

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6C/04/wKiom1U9rtCichTRAAEN46srTWY299.jpg "title=" Picture 8.png "alt=" Wkiom1u9rtcichtraaen46srtwy299.jpg "/>

Enter the container

The Docker 1.3 version provides a more convenient tool for execto run commands directly within the container.

Docker Exec-ti D130a7e46842/bin/bash

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6C/00/wKioL1U9sEyCfKfCAAEnlNo6yAc049.jpg "title=" Picture 9.png "alt=" Wkiol1u9seycfkfcaaenlno6yac049.jpg "/>

with do not close the container after exit, but continue running in the background

Delete Container

You can use the Docker RM command to remove a container in the terminated state, which is formatted as Docker rm , and the supported options are

-F forcibly terminates and deletes a running container.

-L Removes the connection to the container, but retains the container.

-V Deletes the container mounted data volume,

[email protected] ~]# Docker RM d130a7e46842

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6C/00/wKioL1U9sG2x4LFFAAEdQRuqH5w414.jpg "title=" Picture 10.png "alt=" wkiol1u9sg2x4lffaaedqruqh5w414.jpg "/>

If you want to delete a running container, you can add - F parameter

[email protected] ~]# Docker rm-f e41acf350912

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6C/04/wKiom1U9rx6BQewQAAFhHz1TLm4313.jpg "title=" Picture 11.png "alt=" Wkiom1u9rx6bqewqaafhhz1tlm4313.jpg "/>

Import and Export containers (emphasis)

The export container is to instruct a container that has been created to a file, and the Docker export command can be used regardless of whether the container is in a running state.

[email protected] docker]# Docker export CEC2EEA2F8B6 > Test1.tar

Docker export (ID of container ) > file . Tar

These files can be transferred to other machines, and the container is migrated through import commands on other machines.

Import container

Exported files can be imported using the Docker import command and become mirrored

[email protected] docker]# Cat Test1.tar | Docker IMPORT-TEST/CENTOS:V1

Docker Import-(space) name

[email protected] docker]# Docker images

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6C/04/wKiom1U9rzyyATUHAAFEzWuZO1k037.jpg "title=" Picture 12.png "alt=" Wkiom1u9rzyyatuhaafezwuzo1k037.jpg "/>


Docker five easy-to-use containers

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.