DOCKER the Quick Start Basics

1.docker Profile

  • To solve the problem: the package development environment and run the code to overall operation and maintenance;
    developers can eliminate the use of Docker collaborative coding problems "on my machine can work normal";

2.docker advantage

  • 1. lightweight, quick-second start-up speed
    • 2. Simple, easy to use, active community
    • 3. The standard uniform packaging / deployment / run program
    • 4. Mirroring supports incremental distribution, ease of deployment
    • 5. easy to build a good REST API, also very suitable for automated testing and continuous integration
    • 6. performance, especially memory and IO overhead

3.docker installation

1. Basic Composition

1. Mirror: is a read-only template, a mirror can create a lot of container
2. Container: Container is created with a running instance of the mirror
3. Warehouse: centralized place to store image files

2. Install
	1.centos6.8:
		0.找到阿里云容器镜像服务:镜像加速器,复制自己的专属加速器
		1.yum install -y epel-release //装库EPEL
		2.yum install -y docker-io //安装docker
		3.安装后的配置文件: /etc/sysconfig/docker
			配置other_arg="--registry-mirror=https://你自己的加速器.aliyuncs.com"
				DOCKER_CERT_PATH=/etc/docker
				DOCKER_NOWARN_KERNEL_VERSION=1
		4.启动Docker后台服务:service docker start //重启时retart
		5.docker version
	2.centos7(阿里云服务器):
	
		0.找到阿里云容器镜像服务:镜像加速器,复制自己的专属加速器
		0.1.yum -y upate //防止报错: Error response from daemon: oci runtime error:
										container_linux.go:247: starting container process
		0.2.yum -y install epel-release
		1.yum -y install docker-ce
		2.service docker start  //开机启动
		3.查看版本docker version
		4.vim /etc/docker/daemon.json   //生成并编辑加入下面的json串
		5.{
			"registry-mirrors": ["https://你自己的加速器.aliyuncs.com"]
		  }     //告诉centos7去这个地址找
		6.systemctl daemon-reload
		7.systemctl restart docker //重启时retart
	3.卸载centos7
		1.systemctl stop docker
		2.yum remove docker  docker-common docker-selinux dockesr-engine //卸载
		3.rm -rf /var/lib/docker

4.docker operating principle

What 1.run command did?

2.docker underlying principle
  • 1.docker of difference and vm
    Here Insert Picture Description

5.docker commonly used commands

  • Help command
	1.docker version //查看版本
	2.docker info //docker信息描述
	3.docker --help //帮助命令
  • Mirroring Command
	1.docker images //列出本机上的镜像
	 -a == all //全镜像
	 -q //只显示id
	 -qa //显示全id
	 --digests //显示摘要信息
	 --no-trunc //显示完整的镜像信息

Here Insert Picture Description

	2.docker search XXX //在docker hub查找镜像XXX
	-s //点赞数筛选超过的
	3.docker pull XXX //下载镜像XXX 等价 docker pull XXX:latest 最新版
	4.docker rmi XXX //删除XXX镜像
	-f XXX //删除单个
	-f XXX XXX //删除多个
	-f $(docker images -qa) //删除全部
  • Containers (primary core when pulling the pull, without considering the hardware configuration) command
    • The container can be as simple version of the LINUX environment
	1.docker run [OPTIONS]
	-it XXXID //启动交互式容器
		1.1 exit //容器停止退出
		1.2 ctrl+P+Q //容器不停止推出

Here Insert Picture Description

	2.docker ps [OPTIONS] //docker跑了几个容器

Here Insert Picture Description

	3.docker start XXXID //启动容器
	4.docker restart XXXID //重启容器
	5.docker stop XXXID //停止容器
		docker kill XXXID //强制关闭容器
	6.docker rm XXXID //删除已停止的容器
		-f XXXID //删除没有停止的容器
	7.docker rm -f $(docker ps -a -q) //删除全部容器
  • Container emphasis
	1.docker run -d XXX  //后台启动返回ID ,自守护模式,不交互

Here Insert Picture Description

	2.docker logs -f -t --tail XXXID //查看容器日志
	-t 是加入时间戳
	-f 是跟随最新的日志打印
	--tail 显示最后多少条
	3.docker top XXXID //查看容器内运行的进程
	4.docker inspect XXXID //查看容器内部细节
	5.docker attach XXXID //重新进入容器(当执行ctrl+P+Q之后)
	6.docker exec -t XXXID ls -l /tmp //不需要进入容器内部,直接的到结果
	7.docker cp XXXID:/tmp/yum.log  /root/abc //从容器内拷贝数据到主机上
  • Commonly used commands graphic
    Here Insert Picture Description
  • help command in translation
attach    Attach to a running container                 # 当前 shell 下 attach 连接指定运行镜像
build     Build an image from a Dockerfile              # 通过 Dockerfile 定制镜像
commit    Create a new image from a container changes   # 提交当前容器为新的镜像
cp        Copy files/folders from the containers filesystem to the host path   #从容器中拷贝指定文件或者目录到宿主机中
create    Create a new container                        # 创建一个新的容器,同 run,但不启动容器
diff      Inspect changes on a container's filesystem   # 查看 docker 容器变化
events    Get real time events from the server          # 从 docker 服务获取容器实时事件
exec      Run a command in an existing container        # 在已存在的容器上运行命令
export    Stream the contents of a container as a tar archive   # 导出容器的内容流作为一个 tar 归档文件[对应 import ]
history   Show the history of an image                  # 展示一个镜像形成历史
images    List images                                   # 列出系统当前镜像
import    Create a new filesystem image from the contents of a tarball # 从tar包中的内容创建一个新的文件系统映像[对应export]
info      Display system-wide information               # 显示系统相关信息
inspect   Return low-level information on a container   # 查看容器详细信息
kill      Kill a running container                      # kill 指定 docker 容器
load      Load an image from a tar archive              # 从一个 tar 包中加载一个镜像[对应 save]
login     Register or Login to the docker registry server    # 注册或者登陆一个 docker 源服务器
logout    Log out from a Docker registry server          # 从当前 Docker registry 退出
logs      Fetch the logs of a container                 # 输出当前容器日志信息
port      Lookup the public-facing port which is NAT-ed to PRIVATE_PORT    # 查看映射端口对应的容器内部源端口
pause     Pause all processes within a container        # 暂停容器
ps        List containers                               # 列出容器列表
pull      Pull an image or a repository from the docker registry server   # 从docker镜像源服务器拉取指定镜像或者库镜像
push      Push an image or a repository to the docker registry server    # 推送指定镜像或者库镜像至docker源服务器
restart   Restart a running container                   # 重启运行的容器
rm        Remove one or more containers                 # 移除一个或者多个容器
rmi       Remove one or more images             # 移除一个或多个镜像[无容器使用该镜像才可删除,否则需删除相关容器才可继续或 -f 强制删除]
run       Run a command in a new container              # 创建一个新的容器并运行一个命令
save      Save an image to a tar archive                # 保存一个镜像为一个 tar 包[对应 load]
search    Search for an image on the Docker Hub         # 在 docker hub 中搜索镜像
start     Start a stopped containers                    # 启动容器
stop      Stop a running containers                     # 停止容器
tag       Tag an image into a repository                # 给源中镜像打标签
top       Lookup the running processes of a container   # 查看容器中运行的进程信息
unpause   Unpause a paused container                    # 取消暂停容器
version   Show the docker version information           # 查看 docker 版本号
wait      Block until a container stops, then print its exit code   # 截取容器停止时的退出状态值
Published 12 original articles · won praise 2 · Views 430

Guess you like

Origin blog.csdn.net/weixin_43308406/article/details/101447141