docker笔记1


一、为什么要学docker?

  在过去,开发人员编写的代码在不同的环境中运行时常常面临一些问题,例如==“在我的机器上可以运行,但在你的机器上却不行”的情况。这种问题部分原因是因为开发和生产环境之间的配置差异,导致了应用程序在不同环境中的行为不一致。
  此外,虚拟机技术虽然能够解决一部分环境隔离和配置一致性的问题,但它们过于笨重,启动慢且占用资源多(每个虚拟机中都要装相应的操作系统)。因此,人们开始寻求一种更加轻量级、灵活且便于管理的解决方案。
  基于上述的问题,docker应运而生。Docker 的核心概念是容器化,它将应用程序及其所有依赖项(例如代码、运行时、库、环境变量等)打包到一个称为容器的独立运行环境中。这些容器可以在任何支持 Docker 的平台上运行,而不受底层操作系统或硬件的影响。

在这里插入图片描述

二、docker是什么

  Docker 是一个开放源代码的软件容器平台,它允许开发者、系统管理员和运维团队将应用程序及其依赖项打包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app), 更重要的是容器性能开销极低。

在这里插入图片描述

  • 镜像(image),类似于一个模板,根据这个模板可以创建很多的副本。假设你要制作一个蛋糕,你需要一个蛋糕模具来确保每次制作的蛋糕形状都一致。Docker镜像就像是这个蛋糕模具,每次你用这个模具(镜像)来“烘焙”(启动容器),都会得到一个形状一致的“蛋糕”(容器实例)
  • 容器(container),就是一个简易的Linux系统。
  • 仓库(repository),存放镜像的地方,类似maven,有私有仓库和公有仓库。

三、docker安装

环境:使用Centos 7即以上版本即可
安装:

# 1、卸载旧的版本
sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
                  
# 2、需要的安装包
sudo 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相关的源 docker-ce 社区 ee 企业版
yum install docker-ce docker-ce-cli containerd.io

# 5、启动docker
systemctl start docker

# 6、使用docker version 查看是否安装成功
docker version
# 7、docker run hello-world
docker run hello-world
# 8、查看下载的这个 hello-world 镜像
docker images

问题:在执行第二步安装的时候sudo yum install -y yum-utils发现报错:

Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=genclo error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"
 One of the configured repositories failed (未知),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: base/7/x86_64

通过查阅文章,ping主机地址和www.baidu.com地址都没问题,说明不是网络或者DNS的问题,然后尝试执行下面的命令:

尝试从阿里云(Aliyun)的镜像站点下载CentOS 6的YUM仓库配置文件,并将其保存到/etc/yum.repos.d/目录

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

配置完按顺序执行

yum clean all

yum makecache

yum -y update

经过上述的执行命令后,在执行sudo yum install -y yum-utils成功了,然后安装后面命令成功安装docker:

[root@ser878629168738 /]# docker version
Client: Docker Engine - Community
 Version:           26.1.4
 API version:       1.45
 Go version:        go1.21.11
 Git commit:        5650f9b
 Built:             Wed Jun  5 11:32:04 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.1.4
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.11
  Git commit:       de5c9cf
  Built:            Wed Jun  5 11:31:02 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.33
  GitCommit:        d2d58213f83a351ca8f528a95fbd145f5654e957
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

相关推荐

  1. Docker:学习笔记1

    2024-07-10 05:56:03       30 阅读
  2. docker学习笔记1:什么是docker

    2024-07-10 05:56:03       31 阅读
  3. <span style='color:red;'>docker</span>-<span style='color:red;'>1</span>

    docker-1

    2024-07-10 05:56:03      28 阅读
  4. docker笔记

    2024-07-10 05:56:03       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 05:56:03       99 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 05:56:03       107 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 05:56:03       90 阅读
  4. Python语言-面向对象

    2024-07-10 05:56:03       98 阅读

热门阅读

  1. 怎么把数据转换成百度k线图

    2024-07-10 05:56:03       30 阅读
  2. 什么是软件定义安全SDSec

    2024-07-10 05:56:03       28 阅读
  3. [数仓]十、离线数仓(安全集群实战)

    2024-07-10 05:56:03       25 阅读
  4. pycharm中快捷键汇总

    2024-07-10 05:56:03       28 阅读
  5. Python爬虫原理以及3个小案例(源码)

    2024-07-10 05:56:03       30 阅读
  6. PySpark 中 RDD 与 DataFrame 的不同应用场景

    2024-07-10 05:56:03       33 阅读
  7. 【OCC学习18】三维几何对象工具包:TKG3d

    2024-07-10 05:56:03       31 阅读