Docker学习笔记1

Docker为什么会出现

        环境配置十分麻烦,每个机器都需要部署环境(集群redis,ES,Hadoop...)

        发布项目jar(redis,mysql,jdk,es)项目带上环境打包

        之前在服务器配置一个应用的环境redis,mysql,jdk,es,hadoop,无法跨平台

        windows发布到linux

        传统:开发jar,运维来做

        现在:开发打包部署上线,一条龙服务

        java -- apk -- 发布(应用商店) --- xxx使用apk -- 安装就可以用

        jar -- jar(环境)-- 打包项目带上环境(镜像)-- (docker仓库)-- 下载发布的镜像 -- 直接运行

什么是Docker?

        docker是基于go语言开发的,它是一个开源项目

        docker核心思想来自集装箱

        jre -- 多个应用(端口冲突) -- 原来都是交叉的

        隔离: docker核心思想  打包装箱,每一个箱子是互相隔离的。

        docker通过隔离机制可以将服务器空间充分的利用

Docker历史

        2010,几个搞it的年轻人,就在美国成立了一家公司  dotcloud

        做一些 pass 的云计算服务,linux有关容器技术

        他们将自己的技术(容器化技术)命名为Docker

        2013年,Docker开源每个月更新一个版本

        2014年4月,docker1.0发布

Docker VS 虚拟机

        虚拟机:在window中装一个vmware,通过这个软件虚拟出来一台或多台电脑,很笨重

        虚拟机也是属于虚拟化技术,Docker容器化技术,也是虚拟化技术

        vm:linux centos 原生镜像(一个电脑)  隔离需要开启多个虚拟机

        docker :隔离,镜像(最核心的环境 + jdk + mysql)十分小巧,运行镜像就可以

不同点:

        1. 传统虚拟机,虚拟出一套硬件,运行一个完整的操作系统,然后在这个系统上安装和运行软件

        2. 容器的应用直接运行在宿主机的内核,容器是没有内核的,也没用虚拟我们的硬件,所以很轻便

        3. 每个容器是相互隔离的,每个容器都有自己的文件系统,互不影响

        docker官网: Empowering App Development for Developers | Docker

        docker文档地址:Docker Documentation | Docker Documentation  

        docker仓库地址:Docker Hub  

 Docker的优势(DevOps(开发,运维))

        应用更快速的交付和部署

                传统:一堆帮助文档,安装程序

                Docker:打包镜像发布测试,一键运行

        更便捷的升级和扩容

                使用了Docker后,我们部署项目就像搭积木一样

                项目打包为一个镜像,

        更简单的系统运维

                在容器化之后,我们的开发,测试环境都是高度一致的

        更高效的计算机资源利用

                Docker是内核级别的虚拟化,它可以在一个物理机上运行很多个容器实例

Docker的基本组成

查看源图像

镜像(image)

docker镜像就好像一个模板,可以通过这个模板来创建容器服务,tomcat镜像==>run==>tomcat01 容器(提供服务器),通过这个镜像可以创建多个容器(最终服务运行或者项目运行就是在容器中)

容器(container)

docker利用容器技术,独立运行一个或者一组应用,通过容器创建

启动,停止,删除,基本命令

仓库(repository)

仓库就是存放镜像的地方

仓库分为共有仓库和私有仓库

Docker Hub(默认是国外的)

安装Docker

环境准备

CentOS 7

环境查看

#系统内核是3.10以上的

[cong@localhost /]$ uname -r
3.10.0-1160.el7.x86_64

#系统版本

[cong@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"

安装 

 帮助文档

 # 1. 卸载旧的环境

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

# 2. 需要的安装包

yum install -y yum-utils

# 3. 设置镜像的仓库(推荐使用阿里云的,十分快)

yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 更新yum软件包的索引

yum makecache fast

# 4. 安装docker相关的内容

yum install docker-ce docker-ce-cli containerd.io

# 5. 启动docker

systemctl start docker

# 6. 使用docker version 是否安装成功

[root@localhost cong]# docker version
Client: Docker Engine - Community
 Version:           20.10.12
 API version:       1.41
 Go version:        go1.16.12
 Git commit:        e91ed57
 Built:             Mon Dec 13 11:45:41 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.12
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.12
  Git commit:       459d0df
  Built:            Mon Dec 13 11:44:05 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.12
  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

# 7. docker run hello-world

[root@localhost cong]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Already exists 
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
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/

# 8. 查看一下下载的这个hello-world版本

[root@localhost cong]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   3 months ago   13.3kB

 了解卸载docker 

# 1. 卸载依赖

yum remove docker-ce docker-ce-cli containerd.io

# 2. 删除目录

rm -rf /var/lib/docker

# /var/lib/docker   docker的默认工作路径

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值