Docker容器安装及基本体验

本文详细介绍了Docker的安装过程,包括卸载旧版、安装依赖、设置仓库和启动Docker。接着讲解了Docker的基本概念,如镜像、容器和仓库,并对比了Docker与虚拟机的区别。此外,还提供了Docker常用命令的体验,如拉取、查看镜像,创建和管理容器,以及Docker在web应用部署和容器间关联的实际应用案例。
摘要由CSDN通过智能技术生成

安装Docker

卸载旧版的Docker

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

安装依赖

sudo yum install -y yum-utils

设置docker仓库

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

安装 Docker 引擎

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

启动 Docker

sudo systemctl start docker

测试Docker 是否安装成功

执行Docker run hello-word 见到以下输出 即安装成功

[root@iZj6ceofz5f9y3zvpwrig1Z ~]# docker run 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:
 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/

Docker简介

Docker应用场景

  • web应用的自动化打包和发布
  • 自动化测试和持续继承 发布
  • 在服务型环境中部署和调整数据库或其他的后台应用
  • 使用Docker可以实现开发人员的开发环境, 测试人员的测试环境,运维人员的生产的环境的一致性

在这里插入图片描述

  • Docker 借鉴了标准集装箱的慨念 标准集装箱 将货物运往时间各地

    Docker将这个模型运用到自己的设计中 唯一不同的是 集装箱运输货物 而Docker 运输软件

Docker与虚拟机的区别

  • 虚拟机:

    • ​ 虚拟机 需要有单独的OS操作系统 操作系统有时候就是一到两个G起步的
    • 而且 需要手动分配CPU和内存资源 ,操作系统就需要很大一部分的硬件资源
    • 每一个虚拟机 都有自己的操作系统
    • 虚拟机需要开机时间
  • Docker:

    • 在这里插入图片描述

    • Docker 容器是在操作系统层面上实现虚拟化的 直接复用本地宿主机的操作系统

      而传统虚拟机则是在硬件层面直接实现虚拟化 与传统的虚拟机相比 Docker优势体现为启动快 占用体积小

Docker的三个概念

在这里插入图片描述

镜像(image)

Docker inage可以理解为创建Docker容器的模板(静态只读)相当于是一个root文件系统 镜像和容器的关系

就像面向对象程序设计中的类和实例一样 镜像是静态的定义 容器是镜像运行时的实体

容器(Contalner)

容器是一个运行时环境 是镜像的一个运行状态 是镜像执行的动态表现 容器可以被创建 启动停止删除 暂停等

Docker容器通过Docker镜像来创建

仓库(Repository)

仓库用来保存镜像 可以理解为代码控制中的代码仓库

Docker基本使用

Docker命令基本体验

docker images 查看镜像

查看当前images 内有那些镜像

[root@iZj6ceofz5f9y3zvpwrig1Z bin]# docker images 
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   3 months ago   13.3kB

docker pull 拉取镜像到本地

比如要拉取 nginx镜像: docker pull nginx (默认拉取最新版本)

拉取之前先docker images 看一下 现在是没有的

[root@iZj6ceofz5f9y3zvpwrig1Z bin]# docker images 
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   3 months ago   13.3kB

然后pull 拉取镜像

[root@iZj6ceofz5f9y3zvpwrig1Z ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
b4d181a07f80: Pull complete 
edb81c9bc1f5: Pull complete 
b21fed559b9f: Pull complete 
03e6a2452751: Pull complete 
b82f7f888feb: Pull complete 
5430e98eba64: Pull complete 
Digest: sha256:47ae43cdfc7064d28800bc42e79a429540c7c80168e8c8952778c0d5af1c09db
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

然后在docker images 看一下

[root@iZj6ceofz5f9y3zvpwrig1Z ~]# docker images 
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
nginx         latest    4f380adfc10f   11 days ago    133MB
hello-world   latest    d1165f221234   4 months ago   13.3kB
docker image inspect 查看镜像详细信息

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值