[Docker] docker container 04 using

 main content:

    O, concept

    First, create & launch container

    Second, the View container container logs & View

    Third, enter & Stop & delete container 

    IV & Import Export containers

    Five other containers command

 

O, concept

Docker container is a mirror image of the running instance, a container with a required run-time writable file layer, and the image is a static read-only file. You can use the command to view the Docker docker container help support the operation of container sub-command.

 

First, create a boot image &

 1.1.  Create a container command (man docker-create the parameters available to view) command so that the new vessel is stopped.

   语法:docker create [OPTIONS] CONTAINER [COMMAND] [ARG...]

   Apline create a container with 3.8 version:

docker create -it alpine:3.8

 

 1.2.  Start container command (man docker-start parameters can be viewed), to start the container has been created.

   语法:docker start [OPTIONS] [CONTAINER] [CONTAINER...]

   CONTAINER: represents a plurality of containers can be started simultaneously.

 

 1.3.  Create and launch container command (man docker-run parameters can be viewed), after stop container you can also use the command to start the container.

   语法:docker run [OPTIONS] CONTAINER [COMMAND]

   Common parameters:

    -it: -i represents the standard input is held open, -t indicates whether to allocate a pseudo-terminal;

    -d: Indicates whether the container runs in the background;

    --rm: Indicates whether to delete the container exit;

    -p: a map showing port;

    --name: alias specified container;

   When creating a run and start the container, Docker in the background standards are as follows:

    - Check whether there is a local mirror, then download the image does not exist;

    - the use of image creation and launch container;

    - a file system assigned to the container, and one read-only and writable mirror mount the outer layer;

    - bridging host configuration from the host bridge interface to a virtual interface to the container;

    - configure an IP address from the address pool container to the bridge;

    - execution of the application specified by the user;

    - after the implementation of the container is automatically terminated;

   Create and launch container, and allow user interaction (exit or ctrl + d to Quit):

docker run -it alpine:3.8 /bin/sh

 

 1.4.  Restart command container (man docker-restart parameter can be viewed).

   语法:docker restart [OPTIONS] CONTAINER [COMMAND]

   This command will run in a container before termination, then restart.

 

Second, the View container container logs & View

 2.1.  See container list command (man docker-ps parameters can be viewed).

   Syntax: Docker PS [the OPTIONS]

   Common parameters:

    -a, --all: show all containers, comprising a container is stopped;

    -f, --filter: filter container (e.g. -f --name = ne $, ne represents the ending vessel name);

    -l, --latest: display container recently created;

    --no-trunc: do not truncate the output of content (sometimes incomplete command that is too long column appears);

 

2.2.  See container information command (man docker-inspect parameters can be viewed). 

   Syntax: Docker the Inspect [the OPTIONS] NAME | ID

   See vessel network configuration, grep to see which filter configuration, -A specified number of rows to be displayed:

docker inspect 8d | grep Networks -A 20

 

 

2.3.  Inner vessel view process (parameter available to man docker-top view). 

   Syntax: Docker Top CONTAINER

 

2.4.  See container statistics (man docker-stats parameters can be viewed) is displayed using the CPU, memory, storage, network situation information. 

   Syntax: Docker stats [the OPTIONS] [CONTAINER ...]

docker stats -a

 

2.5.  See outputting content container (man docker-logs parameters available to view), is used to obtain the output container. 

   语法:docker logs [OPTIONS] CONTAINER

   Common parameters:

    -f, -follow: sustained output;

    -tail string: the output of a number of recent log:

    -t, -timestamps: display timestamp information;

    -since string: a log output start time;

    -until string: you Log output before a certain time;

    -details: print details;

 

Third, enter & Stop & delete container

 3.1  into the container command (man docker-exec parameters can be viewed).

   语法:docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

   Into the container:

docker exec -it 8d /bin/sh

   

 

 3.2. 暂停&恢复容器命令(参数可用man docker-pause 或 man docker-unpause来查看)。

   语法:docker pause CONTAINER [CONTAINER...]  /  docker unpause CONTAINER [CONTAINER...]

   暂停和恢复容器:

 

 3.3. 终止容器命令(参数可用man docker-stop)。

   语法:docker stop [OPTIONS] CONTAINER [CONTAINER...]

   这个命令会先向容器发送SIGTERM信号,等待一段超时时间后(默认10s),再发送SIGKILL信号来终止容器。

   清除所有处于停止状态的容器:

docker container prune

 

3.4. 删除容器命令(参数可用man docker-rm)。

   语法:docker rm [OPTIONS] CONTAINER [CONTAINER...]

   常用参数:

    -f, --force:是否强行终止一个运行中的容器,在没有-f参数时,rm只能删除已经停止或退出状态的容器,不能删除运行中的容器;

    -l, --link:删除容器的连接,但保留容器;

    -v, --volumes:删除容器挂载的数据卷;

 

四、导入&导出容器

 4.1. 导出容器命令(参数可用man docker-export来查看),用于导出容器到tar文件,这个tar文件是容器当时的快照状态。

   语法:docker export [OPTIONS] CONTAINER

   将容器在当前目录导出为alpine.tar的文件:

docker export -o alpine2.tar 8d
或
docker export > alpine2.tar 8d

 

 4.2. 导入容器命令(参数可用man docker-import来查看),用于导入tar文件变为镜像。

   语法:docker import [OPTIONS] FILE|URL [REPOSITORY[:TAG]]

   将alpine.tar容器快照到本地镜像库,和load的区别在于:镜像存储文件会保存所有历史记录,而容器快照文件会丢弃所有历史记录和元数据信息,在导入时可以重新指定标签等元数据信息。

docker import alpine2.tar alpine:2

 

 

五、其他容器命令

 5.1. 复制文件命令(参数可用man docker-cp来查看),用于容器和主机之间复制文件。

   语法:docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH | docker cp [OPTIONS] SRC_PATH CONTAINER:DEST_PATH

   复制本地文件到容器里:

vi test.sh
docker cp test.sh 8d:/

   复制容器文件到本地:

docker cp 8d:/etc/passwd /root

 

 5.2. 查看容器变更命令(参数可用man docker-diff来查看)。

   语法:docker diff CONTAINER

 

 5.3. 查看容器端口映射(参数可用man docker-port来查看): 

   语法:docker port CONTAINER

 

 5.4. 更新容器配置(参数可用man docker-update来查看),用于更新容器一些运行时配置: 

   语法:docker port [OPTIONS] CONTAINER [CONTAINER...]

 

Guess you like

Origin www.cnblogs.com/allbetter/p/11062271.html