浅谈对docker的认识

浅谈对docker的认识

docker入门

1.1 Docker为什么火
1.2 Docker是什么
1.3 为什么要使用Docker
1.4 Docker与虚拟化区别
1.5 Docker Engine
1.6 Docker 体系结构
1.7 Docker 应用场景
场景一、节省项目环境部署时间
场景二、环境一致性
场景三、持续集成
场景四、微服务
总结:开箱即用、快速部署、可移植强、环境隔离。

docker安装

2.1 安装Docker 
curl -o /etc/yum.repos.d/docker-ce.repo  https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
	yum install docker-ce -y
	systemctl start docker
	systemctl enable 
2.1.1 调整镜像源从国内获取
[root@container ~]# cat /etc/docker/daemon.json
{
  "registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"]
}
2.1.2 调整docker数据存储位置
[root@container ~]# cat /etc/docker/daemon.json
{
  "registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"],
   "graph": "/data/docker"
}

docker镜像

  • 3.1 什么是镜像?
    镜像是一推程序和文件的集合。封装了业务需要运行的代码、环境、配置文件等 ( 只读的实例 )

  • 3.2 镜像能干什么?
    镜像可以启动容器,容器需要依赖镜像才可以启动。

  • 3.3 如何使用镜像运行容器
    docker run hello-world

  • 3.4 镜像的基本操作。搜索、下载、查看、导入、导出、删除、上传

1、搜索镜像
[root@container ~]# docker  search centos   
2、下载镜像
[root@container ~]# docker  pull centos:7
3、查看镜像列表
[root@container ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              7                   5e35e350aded        4 months ago        203MB
hello-world         latest              fce289e99eb9        14 months ago 
1.84kB
[root@container ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              7                   5e35e350aded        4 months ago        203MB
hello-world         latest              fce289e99eb9        14 months ago       1.84kB
4、删除镜像
[root@container ~]# docker image rmi  fce289e99eb9
[root@container ~]# docker image rmi -f  fce289e99eb9
5、备份镜像
[root@container ~]# docker save centos:7  > /opt/centos.tar.gz
6、恢复镜像
[root@container ~]# docker  load < /opt/centos.tar.gz

docker容器

4.1 什么是容器
容器是镜像运行的一个实例,当启动搞一个容器就好像虚拟机程序启动了一台VM一样。
4.2 容器能运行什么

4.3 启动第一个容器

	[root@container ~]# docker run -it centos:7 /bin/bash

4.4 容器运行的参数含义
docker run 表示要启动一个容器
-i:表示 启动一个可交互的容器。并且持续打开标准输入
-t:表示使用终端关联到容器的标准输入输出上
IMAGE:表示我们需要运行的镜像
COMMAND:运行该镜像需要执行的命

4.5 如何运行一个自启动的容器

4.5.1 运行容器
[root@localhost ~]# docker run -it  --rm  centos:7 echo "hello docker "
hello docker
[root@localhost ~]# docker run --name=mycentos centos:7 echo "hello world"
[root@localhost ~]# docker ps -a 
CONTAINER ID   IMAGE      COMMAND                CREATED          STATUS                      PORTS     NAMES
1679608b8af1   centos:7   "echo 'hello world'"   37 seconds ago   Exited (0) 36 seconds ago             mycentos
[root@localhost ~]# docker run -itd centos:7 /bin/bash 
56b3a38318239991525b007b2b493cfe5988b95d10b5a1621e4ad1102a41adf4
4.5.2 运行一个测试的容器
[root@localhost ~]# docker run  --rm centos:7 echo "hello rm"hello rm
4.5.3 启动|停止|restart
[root@localhost ~]# docker  stop 56b3a3831823
56b3a3831823
[root@localhost ~]# docker start 56b3a3831823
56b3a3831823
[root@localhost ~]# docker restart 56b3a3831823
56b3a3831823
4.5.4 查看状态
[root@localhost ~]# docker info 
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 2
  Running: 1
  Paused: 0
  Stopped: 1
 Images: 5
 Server Version: 20.10.17
  • 如何进入一个容器
[root@localhost ~]# docker exec -it 56b3a3831823 /bin/bash 
[root@56b3a3831823 /]# 
  • 清理容器
[root@localhost ~]# docker rm -f $(docker ps -a -q)
56b3a3831823
posted @ 2022-07-01 10:06  断尽的记忆  阅读(61)  评论(0编辑  收藏  举报