Docker from entry to the master (a)
BACKGROUND a. (Physical -> Virtualization (the hypervisor resource isolation) -> of the container)
About two .docker
Docker is an open source application container engine that lets developers can package their applications and dependencies into a portable mirror, and then publish to any of the popular Linux on a Windows machine or can be achieved virtualization . The container is full use of the sandbox mechanism will not have any interface with each other. Standardized environment: one package, publish everywhere, providing application packaging, deployment and operation of container platforms.
2.1 with the container mirror
Mirror: the file read-only, providing a complete hardware and software resources to run the program, the "container" application;
Container: Example mirrored by Docker responsible for creating, between the container isolated from each other;
Three .docker installation
[root@centos7 ~]# uname -r
3.10.0-1062.9.1.el7.x86_64
3.1 uninstall the old version
[root@centos7 ~]# yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
[root@centos7 ~]# yum remove docker-ce
3.2 安装docker-ce
1.安装依赖包
[root@centos7 lib]# yum install -y yum-utils device-mapper-persistent-data lvm2
2.替换国外安装源
[root@centos7 lib]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
3.更新yum软件包索引
[root@centos7 lib]# yum makecache fast
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/2): docker-ce-stable/x86_64/updateinfo | 55 B 00:00:00
(2/2): docker-ce-stable/x86_64/primary_db | 37 kB 00:00:00
元数据缓存已建立
4.安装最新版本docker-ce
[root@centos7 lib]# yum -y install docker-ce
#安装指定版本docker-ce可使用以下命令查看
yum list docker-ce.x86_64 --showduplicates | sort -r
# 安装完成之后可以使用命令查看
[root@centos7 lib]# docker version
5.启动docker服务
[root@centos7 lib]# service docker start
3.3 验证docker运行
1.拉取镜像文件
[root@centos7 lib]docker pull hello-world
2.运行镜像文件
[root@centos7 lib]docker run hello-world
四.docker的镜像加速配置(国外镜像有可能无法成功下载)
4.1 注册登录开通阿里云容器镜像服务 https://account.aliyun.com/login/login.htm
4.2配置镜像加速服务地址信息
1.创建启动文件夹 sudo mkdir -p /etc/docker 2.创建镜像加速文件 sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://8dvlx2wz.mirror.aliyuncs.com"] } EOF #vim /etc/docker/daemon.json #{ # "registry-mirrors": ["https://8dvlx2wz.mirror.aliyuncs.com"]
#} 3.重载配置文件 sudo systemctl daemon-reload 4.重启docker服务 sudo systemctl restart docker
五.docker的执行流程
5.1 docker常用命令
1.docker pull 镜像名<:tags版本号> - 从远程仓库抽取镜像 2.docker images - 查看本地镜像 3.docker run 镜像名<:tags版本号> - 创建容器,启动应用 4.docker ps - 查看正在运行中的镜像 5.docker rm <-f 强制删除> 容器id - 删除容器 6.docker rmi <-f 强制删除> 镜像名:<:tags版本号> - 删除镜像
5.2 安装Tomcat应用
1.拉取Tomcat镜像
1.docker pull tomcat
2.运行Tomcat
docker run -p 主机端口:容器端口 镜像ID或镜像名:TAG