1、docker 是什么 没有 docker 之前,需要把一套环境用到的所有工具都部署一遍,花费的时间非常久。 有了 docker 之后,你只需要把环境打包成一个镜像,复制到另外一台服务器上安装镜像即可。
400 x 172
官网:www.docker.com/ docker 能干什么? 虚拟化软件运行环境,以最小的代价换取最大的资源。比如以前一台服务器只能同时跑 3 个 Redis,用了 docker 之后能跑 30 个。并且每个 Redis 是相互隔离的,这也是 docker 图标上集装箱所想表达的思想。 2、docker 中的名词概念
728 x 388 982 x 523
仓库(repository):Docker hub,存放在镜像的地方,国内可配置镜像加速下载。 镜像(image):是一个模块,可基于此模板运行处多个容器。 容器(container):通过镜像创建的独立运行的一个或一组应用。 3、安装 docker docker 文档:docs.docker.com/
728 x 346 1849 x 880
Linux 系统要求 CentOS 7 或者更高版本。 卸载老版本
卸载老版本
$ sudo yum remove docker
docker-client
docker-client-latest
docker-common
docker-latest
docker-latest-logrotate
docker-logrotate
docker-engine
删除资源目录
rm -rf /var/lib/docker 配置国内镜像加速 mkdir -p /etc/docker vi daemon.json { "registry-mirrors": ["hub-mirror.c.163.com"] }
systemctl daemon-reload systemctl restart docker 4、Hello World [root@localhost ~]# docker run hello-world #############################从docker hub下载hello-world镜像############################### Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 0e03bdcc26d7: Pull complete Digest: sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec Status: Downloaded newer image for hello-world:latest ############################运行hello-world容器############################################ Hello from Docker! This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
- The Docker client contacted the Docker daemon.
- The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)
- The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
- The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID: hub.docker.com/
For more examples and ideas, visit: docs.docker.com/get-started… docker hello-world 运行流程 docker 先在本地寻找 hello-world 镜像没有找到就会去 docker hub 中下载,下载完成之后 docker 运行容器 hello-world,后台会有一个守护进程,所谓的守护进程可以理解为一个 24 小时不中断运行的程序。我们通过 docker 命令调用守护进程,执行对应的方法完成操作。 docker 底层原理图
500 x 274
docker 为什么快,因为他不需要 Guest OS, Guest OS 就是你在虚拟机中安装的 CentOS、Ubuntu,Guest OS 启动时需要进行很多引导操作,非常消耗性能。而 docker 直接利用宿主机的内容加上 docker engine 就能运行容器,极大的节省了性能开销。所以说 docker 是秒级,虚拟机是分钟级。