二、Docker:安装

其他文章:

一、Docker:概述

二、Docker:安装

三、Docker:命令

四、Docker:可视化管理

五、Docker:镜像(image)

六、Docker:数据卷

七、Docker:DockerFile

八、Docker:Docker网络原理

九、Docker:IDEA整合Docker

----------------------------------------------------------------

二、安装

docker的架构图

名词

镜像 image

docker镜像就好比一个模板,可以通过这个模板来创建容器服务,Tomcat镜像–》run -->tomcat01容器。通过这个镜像可以创建多个容器(最终服务运行或者项目运行就是在容器中的)。

容器 container

Docker利用容器技术,独立运行一个或一组应用,通过镜像来创建。

仓库 repository

仓库就是存放镜像的地方。

系统要求

centso7以上

测试机器信息:

[root@localhost ~]# 
[root@localhost ~]# uname -r
3.10.0-957.el7.x86_64
[root@localhost ~]# 
[root@localhost ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

[root@localhost ~]# 

安装步骤:

官方地址:https://docs.docker.com/engine/install/centos/

# 1.卸载已经安装的docker
 sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
                  
# 2.安装(安装方式:使用仓库方式安装)
# 2.1安装工具
sudo yum install -y yum-utils

# 2.2.设置镜像仓库
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo # 国外镜像 很慢 不要用
     
sudo yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # 阿里云镜像 推荐

# 3.建议更新yum软件包索引
sudo yum makecache fast
 
# 4.安装docker引擎(默认安装最新版本,也可指定版本)
sudo yum install docker-ce docker-ce-cli containerd.io  # docker-ce:社区版(推荐)  ee是企业版  cli是客户端  containerd是容器相关

# 5.启动docker(作为服务启动)
sudo systemctl start docker
sudo docker version

[root@localhost ~]# sudo systemctl start docker    # 重启systemctl restart docker
[root@localhost ~]# sudo docker version
Client: Docker Engine - Community  # 引擎的客户端信息
 Version:           20.10.6
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        370c289
 Built:             Fri Apr  9 22:45:33 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community # 引擎的服务端信息
 Engine:
  Version:          20.10.6
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       8728dd2
  Built:            Fri Apr  9 22:43:57 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@localhost ~]# 


# 6.测试hello-world镜像
 sudo docker run hello-world
 
[root@localhost ~]# 
[root@localhost ~]#  sudo docker run hello-world
Unable to find image 'hello-world:latest' locally  #本地没有hello-world镜像
latest: Pulling from library/hello-world   # 从远程仓库拉取镜像
b8dfde127a29: Pull complete 
Digest: sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519
Status: Downloaded newer image for hello-world:latest

Hello from Docker! # 镜像运行成功
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. 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:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

[root@localhost ~]# 

# 7.查看拉取的hello-world镜像
[root@localhost ~]# docker images 
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    d1165f221234   7 weeks ago   13.3kB
[root@localhost ~]# 


#--------------以下信息可以了解--------------------#

# 1.卸载docker
sudo yum remove docker-ce docker-ce-cli containerd.io

# 2.删除镜像
 sudo rm -rf /var/lib/docker   # 默认工作路径
 sudo rm -rf /var/lib/containerd
 
 # 2.删除镜像
 sudo rm -rf /var/lib/docker   # 默认工作路径
 sudo rm -rf /var/lib/containerd
 
[root@localhost volumes]# cd  /var/lib/docker
[root@localhost docker]# 
[root@localhost docker]# ls # 这个目录中包括了docker的所有信息  containers  image  network swarm volumes 等
buildkit  containers  image  network  overlay2  plugins  runtimes  swarm  tmp  trust  volumes
[root@localhost docker]# 

docker run的运行流程

底层原理

docker是怎么工作的?

Docker是一个CS架构,Docker的守护进程运行在主机上,通过socket从客户端访问。

DockerServer接收到Docker-Client的指令就会执行这个命令。

client就是执行docker命令的 docker.

容器内的端口和服务器的端口是不一样的,需要映射。

Docker为什么比VM快?

1.Docker的抽象层更少

2.docker是利用宿主机的内核,VM需要的是GuestOS

阿里云镜像加速 一定要配置 否则很慢

参考:https://www.cnblogs.com/allenjing/p/12575972.html

阿里云:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值