Docker use of container

Get a mirror

$ docker pull ubuntu

Start container:

$ docker run -it ubuntu /bin/bash
# 要退出终端,直接输入 exit

Start a stopped running container

$ docker ps -a

Start a stopped running container

$ docker start b750bbbcfd88 

Background process

$ docker run -itd --name ubuntu-test ubuntu /bin/bash

Stop a container

$ docker stop <容器 ID>

The container can be stopped by docker restart restart:

$ docker restart <容器 ID>

Into the container

In use -dparameter, will start after the container into the background. At this time, you want to enter the container can be entered through the following instructions:

  • docker attach: If this container exit ( exit), will cause the vessel to stop.
  • docker exec: Recommend the use of docker execcommand because this exit container terminal, will not lead to the vessel to stop.

exec command:

$ docker exec -it 243c32535da7 /bin/bash

Export and import container

Export Container

$ docker export 1e560fca3906 > ubuntu.tar

Import Container

$ cat docker/ubuntu.tar | docker import - test/ubuntu:v1

or

$ docker import docker/ubuntu.tar test/ubuntu:v1 

You can also import a directory or by specifying a URL, for example:

$ docker import http://example.com/exampleimage.tgz example/imagerepo

Reference Source:
[. 1] https://www.runoob.com/docker/docker-container-usage.html

Published 345 original articles · won praise 374 · views 890 000 +

Guess you like

Origin blog.csdn.net/u011331383/article/details/103950629