Docker tutorial series 03_Docker use

1.Docker all the commands

Here Insert Picture Description

2. Help command

docker version 查看docker版本
docker info 显示全系统信息
docker --help 显示docker相关的所有命令及功能说明

3. Mirror command

3.1 docker images on the image list of the machine

Here Insert Picture Description

REPOSITORY:表示镜像的仓库源
TAG:镜像的标签
IMAGE ID:镜像ID
CREATED:镜像创建时间
SIZE:镜像大小

The same warehouse source can have multiple TAG, on behalf of the warehouse source different versions, we use REPOSITORY: TAG to define different image.

If you do not specify a mirrored version of the label, for example, you only use ubuntu, docker will default ubuntu: latest image

docker images - [options] description

-a 列表本地的所有镜像及子镜像
-q 只显示镜像ID
--digests 显示镜像的摘要信息
--no-trunc 显示完整的镜像信息

3.2 docker seach image search command

If impossible, to put a mirror to accelerate into the cloud Ali

Search the site: https: //hub.docker.com
Here Insert Picture Description
grammar

docker search 镜像名称
docker search 镜像名称  -[options]   说明
--no-trunc 显示完整的镜像描述

Here Insert Picture Description
Here Insert Picture Description

-s 列出收藏数不少于指定值的镜像
Docker search mysql -s 300

Here Insert Picture Description

3.3 docker pull mirror download command

grammar

docker pull 镜像名称:[TAG]
例如:docker pull tomcat:8.5  下载8.5的镜像版本
     dokcer pull tomcat 默认下载最新的tomcat镜像版本 【latest】     

3.4 docker rim mirror delete command

删除单个   docker rmi -f 镜像ID
删除多个   docker rmi -f 镜像ID1 镜像ID2
           docker rmi -f 镜像名:[tag]  镜像名:[tag]
删除全部   docker rmi -f $(docker images -qa)

4. Overview of the container and command

4.1 Overview of container

Mirroring is a lightweight container stand-alone executable software package contains everything required to run it: the code, run-time, system tools, system libraries, settings. Regardless of the environment, containers of the same software can run Linux and Windows applications. The software container isolated from its surroundings, the differences between development and production environments, for example, and help reduce conflict between team running different software on the same infrastructure.
Here Insert Picture Description

1. Lightweight

Docker containers running on a single machine share the machine operating system kernel; and they immediately start to use less memory and calculation. The image constructed by the file system layer, and share common files. This minimizes disk usage, image download faster.

2. Standard

Docker containers based on open standards, runs on all major Linux distributions, Microsoft Windows and any infrastructure (including virtual machines, cloud and bare metal).

3. Security

Docker containers isolating applications from each other and separated from the underlying infrastructure. Docker provides the most powerful default isolation, may limit the application issues in a container, rather than on the entire machine.

4.2 demo premise

There are mirrors to create the container, this is the fundamental requirement (download centos mirror to demonstrate)

docker pull centos

Container and start to create 4.3

4.3.1 Syntax

docker run [options] images [command][args]

4.3.2options Description

Some are a minus, minus some two

-name = "container for the new name": Specify a name for the container;

-d: background container, and returns the container ID, or start the daemon i.e. container;

-i: Run vessel in interactive mode, typically used in conjunction with -t;

-t: reassign a pseudo input terminal into a container, normally used in conjunction with -i;

-P: random port mapping;

-p: Specifies the port mapping, the following four formats

​ ip:hostPort:containerPort

​ ip::containerPort

​ hostPort:containerPort

​ containerPort

4.3.3 Interactive run

A container terminal is running and to open the container

#使用镜像centos:latest以交互模式启动一个容器,在容器内执行/bin/bash命令。
docker run -it centos /bin/bash 

4.4 lists all currently running container

4.4.1 Syntax

docker ps [options]
docker ps  列出当前正在运行的容器

Here Insert Picture Description

4.4.2 options Syntax

-a: lists all currently running container + run-off in history

-l: display container recently created.

-n: display the last n-created container.

Here Insert Picture Description

-q: Silent mode, only the container number.

Here Insert Picture Description
-no-trunc: do not cut output.

Here Insert Picture Description

4.5 Exit container

1, exit: stop the container and exit

2, ctrl + P + Q to exit the container does not stop

4.6 Start Stop Restart container

docker start / stop / restart ID container or container name

4.7 forcibly stop the container

docker kill ID container or container name

4.8 Delete stopped container

#单个删除
docker rm 容器ID
#多个删除
docker rm -f $(docker ps -aq)

5. Other Highlights

5.1 Enabling guard vessel

# Mirroring centos: latest stage after a start mode vessel

docker run -d centos

Question: docker ps -a view, will find that the container has withdrawn

A very important point to note: Docker container running in the background, there must be a foreground process.

If not, run the command vessel has been suspended those commands (such as running top, tail), it is automatically quit.

This is a docker mechanisms, such as your web container, we nginx for example, under normal circumstances, we just need to start to start the service configuration is to be of service. For example, service nginx start

However, to do so, nginx runs as a background process mode, it causes the application is not running in the foreground docker,

After such containers into the background, it will immediately commit suicide because he felt he nothing to do up.

So, the best solution is to run a background process of program you want to run before

to sum up

The vessel must have run a foreground process, not, equivalent container said they were not to do, committed suicide, but when the user starts the tomcat, is not used for a long time, why not hang tomcat

  1. There are projects that are running - not established

    If I webapps empty. Start docker container. It also does not quit

  2. Tomcat start because there will always be a terminal pending

5.2 View container logs

If the program is running in the background, then how to view the log run it?

1, a first program running in the background is output two seconds interval [hello laolei]

 docker run -d centos /bin/sh -c "while true;do echo hello laolei;sleep 2;done"

2, View Log

Docker logs to see inside the container logs

docker logs -tf --tail 10 容器ID

*   -t 是加入时间戳
*   -f 跟随最新的日志打印
*   --tail 数字 显示最后多少条

5.3 View running processes container

docker top 容器ID

5.4 Query internal details of the container

docker inspect 容器ID

5.5-going vessel to enter and interact with the command line

#方式1
docker exec -it 容器ID /bin/bash
#方式2
docker attach 容器ID
#两种方式的区别
exec 在容器中打开新的终端 并且可以启动新的进程

attch 直接进行容器终端,不会启动新的进程

5.6 into the container copy files to the host

docker cp container ID: directory path to the host in the container
Here Insert Picture Description

6. Video Address

https://ke.qq.com/course/469242?taid=3997450616908026&tuin=21f98a63

ps: For the latest free documentation and instructional videos, please add QQ group (627,407,545) receive.

Published 91 original articles · won praise 0 · Views 2497

Guess you like

Origin blog.csdn.net/zhoujunfeng121/article/details/104802024