How to enter and exit the Docker container

Source: Internet
Author: User
Tags docker ps docker run

Reprint please indicate the source: http://blog.csdn.net/dongdong9223/article/details/52998375
This article comes from "I'm a Fish's blog" 1 start Docker service

First you need to know that the start Docker service is:

Service Docker start

Or:

Systemctl Start Docker
2 off Docker service

The Docker service is closed :

Service Docker stop

Or:

Systemctl Stop Docker

The Mirror of Docker is called image, and the container is called container.

For Docker, image is static, similar to the operating system snapshot, while container is dynamic and is the running instance of image.

For example, there is an image name called Ubuntu, so for example now we start the container of this image and go into the bash command line of this container:

Docker Run-t-I. Ubuntu/bin/bash

The official website says so: Docker run:runs a container. Ubuntu:is the image to run as you would. -t:flag assigns a pseudo-tty or terminal inside the new container. -i:flag allows you to make a interactive connection by grabbing the standard in (STDIN) of the container. /bin/bash:launches a bash shell inside our container.

Understanding is simple:

Docker run: Start container

Ubuntu: The image you want to start

-T: Enter terminal

-I : get an interactive connection by getting the input of container

/bin/bash: Start a bash shell in container

This goes into the interior of the container:

root@af8bae53bdd3:/#

If you have a running container, you can run it in the external operating system where container is located:

Docker PS

See this container.

If you want to see all of the container, including running, and not running or sleeping mirrors, run:

Docker Ps-a

If you want to quit:

Ctrl-d

Or:

root@af8bae53bdd3:/# exit
3 Start Docker a container (container) of some image (mirror)

If you want to open this container again, run:

Docker start Goofy_almeida

where "Goofy_almeida" is the name of the container. 4 into the container (container) 4.1 Use the "Docker attach" command to enter

This time container runs in the background, and if you want to enter its terminal, then:

Docker Attach Goofy_almeida

It's OK. 4.2 Use the "Docker exec-it" command to enter

The disadvantage of using the "Docker Attach" command to enter the container (container) is that container exits every time it exits from the container to the foreground.

To exit container, let container still be running in the background, you can use the "Docker exec-it" command. Every time you use this command to enter container, after exiting the container, container still running in the background, the command uses the following method:

Docker exec-it Goofy_almeida/bin/bash

Goofy_almeida: Name of the container to start

/bin/bash: Start a bash shell in container

This container still runs in the background by entering "exit" or by pressing "Ctrl + C" to exit Container:

Docker PS

You can find it. 5 Exit Container

Input:

Exit

Or press the key:

Ctrl + C

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.