Docker Quick Start series (2): container concepts and related operations, docker Quick Start

Source: Internet
Author: User
Tags docker run

Docker Quick Start series (2): container concepts and related operations, docker Quick Start
What is container

To put it simply, an image requires a carrier, which is a container. As mentioned in the previous article, an additional writable file layer will be started after the container loads the image.
Let's take the VM as an example. The VM virtualizes the entire operating system and then runs the reference in it. The container actually runs an application or a group of applications and provides the runtime environment required by the application.

Create a container

Docker starts a container within seconds, which is also more relevant than VM. Therefore, users can create, delete, start, and switch containers at any time, which also reflects the "light" of Docker.

# There are two scenarios for starting a container # 1st is to create a container Based on the image and start docker create-ti ubuntu: 14.04 # create a container # 2nd is to start a "terminated" container docker run ubuntu: 14.04/bin/echo "hello bugall"

When we executeDocker runWhat are the standard operations that Docker performs in the background when it is created and started? This is described in the official document:

1. check whether the attached image exists locally. If it does not exist, it will be automatically downloaded from the remote repository. 2. create a container using the specified image. assign a file system to the container and mount a readable and writable layer on the image (the image should be read-only. bridge a virtual interface from the bridge interface configured on the host to the container. configure an IP address from the address pool to the container. 6. execute user-defined applications 7. after the container is executed, the docker run-ti ubuntu: 14.04/bin/bash #-t option is terminated to assign a Pseudo Terminal to docker and bind it to the standard input of the container, #-I: Keep the standard input of the container open.


Ctrl + d Exit

Daemon Running
Docker run-tid ubuntu: 14.04/bin/bash #-d: Enable the container in a protected state. After Ctrl + d is exited, the container is not closed.

Terminate, start the container
Docker stop [-t | -- time [= 10] # First, send the SIGTERM signal to the container. After a period of time (10 seconds by default), terminate the container by sending the SIGKILL signal.

When the application specified in the container ends, the container automatically terminates.
Docker run-ti ubuntu: 14.04/bin/bashCtrl + d terminates the/bin/bash application instead of the container. Why does the container automatically exit and close? This is because the application set during container startup is closed.

If there is a stop, there is a start. Let's see how to start a terminated container.

Docker start CONTAINER_ID # start the container in the terminated state docker restart CONTAINER_ID # restart a container
Enter container
docker run -tid ubuntu:14.04 /bin/bash

-D parameter the user cannot see the information in the container after starting the container. Sometimes we need to enter the container for some operations. Here we will introduce the method for entering the container.

  • Attach command

    Note:
    Officially speaking to attach, this feature means that when multiple Windows attach to the same container at the same time, all windows will be displayed simultaneously. When a window is blocked, other Windows cannot be operated.

  • Docker 1.3 has provided the exec Method for entering the container in another one.
    Docker exec-ti CONTAINER_ID/bin/bash

Delete container
Docker rm [options] container [container...] -f: -- force = false force terminate and delete a running container-l: -- link = false Delete the container connection, but include-v: -- volumes = false: Delete the volume attached to the container # If you want to delete a running container, you can add the-f parameter. docker will send the SIGKILL signal to the container and terminate the application.
Import and export containers

As mentioned in the previous article, the image import and export function is also available for containers. The export here refers to exporting a container as a file, regardless of whether the container is running or not. Note that the import here is in the form of an image.

# Export docker export CONTAINER> SIGN.tar # import docker import-ubuntu.14.04.1 # view all available docker images commands imported as images

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.