docker学习之基础知识

更新时间:2024-01-22 12:21:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

部公开▲

Docker学习之基础知识

Docker 是一个开源项目,诞生于 2013 年初,最初是 dotCloud 公司内部的一个业余项目。它基于 Google公司推出的 Go 语言实现。

Docker 项目的目标是实现轻量级的操作系统虚拟化解决方案。 Docker 的基础是 Linux 容器(LXC)等技术。在 LXC 的基础上 Docker 进行了进一步的封装,让用户不需要去关心容器的管理,使得操作更为简便。用户操作 Docker 的容器就像操作一个快速轻量级的虚拟机一样简单。

图1虚拟机的Guest OS层和Hypervisor层在docker中被Docker Engine层所替代。虚拟机的Guest OS即为虚拟机安装的操作系统,它是一个完整操作系统内核;虚拟机的Hypervisor层可以简单理解为一个硬件虚拟化平台,它在Host OS是以内核态的驱动存在的。

图1 虚拟机

图二 Docker

docker并没有和虚拟机一样利用一个完全独立的Guest OS实现环境隔离,它利用的是目前Linux内核本身支持的容器方式实现资源和环境隔离。简单的说,docker利用namespace实现系统环境的隔离;利用Cgroup实现资源限制;利用镜像实现根目录环境的隔离。

第1页

部公开▲

1. Docker优势

作为一种新兴的虚拟化方式,Docker 跟传统的虚拟化方式相比具有众多的优势。 首先,Docker 容器的启动可以在秒级实现,这相比传统的虚拟机方式要快得多。 其次,Docker 对系统资源的利用率很高,一台主机上可以同时运行数千个 Docker 容器。 容器除了运行其中应用外,基本不消耗额外的系统资源,使得应用的性能很高,同时系统的开销尽量小。传统虚拟机方式运行 10 个不同的应用就要起 10 个虚拟机,而Docker 只需要启动 10 个隔离的应用即可。

具体说来,Docker 在如下几个方面具有较大的优势: 更快速的交付和部署

对开发和运维(devop)人员来说,最希望的就是一次创建或配置,可以在任意地方正常运行。

更高效的虚拟化

Docker 容器的运行不需要额外的 hypervisor 支持,它是内核级的虚拟化,因此可以实现更高的性能和效率。

1、docker相对于物理机其计算能力几乎没有损耗,而虚拟机对比物理机则有着非常明显的损耗。虚拟机的计算能力损耗在50%左右。

2、运行在docker容器上的程序直接使用的都是实际物理机的硬件资源。因此在CPU、内存利用率上docker将会在效率上有优势;

3、docker利用的是宿主机的内核,而不需要Guest OS。因此,当新建一个容器时,docker 不需要和虚拟机一样重新加载一个操作系统内核,避免了虚拟机启动时所需的系统引导时间和操作系统运行的资源消耗;

4、在应用程序内存访问上,虚拟机的应用程序要进行2次的虚拟内存到物理内存的映射,读写内存的代价比docker的应用程序高。

更轻松的迁移和扩展

Docker 容器几乎可以在任意的平台上运行,包括物理机、虚拟机、公有云、私有云、个人电脑、服务器等。 这种兼容性可以让用户把一个应用程序从一个平台直接迁移到另外一个。

第2页

更简单的管理

部公开▲

使用 Docker,只需要小小的修改,就可以替代以往大量的更新工作。所有的修改都以增量的方式被分发和更新,从而实现自动化并且高效的管理。

与传统虚拟机比较

特性 启动 硬盘使用 性能 系统支持量 秒级 一般为MB 接近原生 单机支持上千个容器 容器 分钟级 一般为GB 弱于 一般几十个 虚拟机 2. Docker劣势

前面的内容主要论述docker相对于虚拟机的优势,但docker也不是完美的系统。相对于虚拟机,docker还存在着以下几个缺点:

? 资源隔离方面不如虚拟机,docker是利用cgroup实现资源限制的,只能限制资源消耗

的最大值,而不能隔绝其他程序占用自己的资源。

? 安全性问题。docker目前并不能分辨具体执行指令的用户,只要一个用户拥有执行

docker的权限,那么他就可以对docker的容器进行所有操作,不管该容器是否是由该用户创建。比如A和B都拥有执行docker的权限,由于docker的server端并不会具体判断docker clinet是由哪个用户发起的,A可以删除B创建的容器,存在一定的安全风险。

? docker目前还在版本的快速更新中,细节功能调整比较大。一些核心模块依赖于高版本

内核,存在版本兼容问题

Docker的基本概念

Docker 包括三个基本概念 ? 镜像(Image) ? 容器(Container) ? 仓库(Repository)

镜像(Image)

Docker 镜像就是一个只读的模板。

例如:一个镜像可以包含一个完整的 ubuntu 操作系统环境,里面仅安装了 Apache 或用户

第3页

部公开▲

需要的其它应用程序。

镜像可以用来创建 Docker 容器。

Docker 提供了一个很简单的机制来创建镜像或者更新现有的镜像,用户甚至可以直接从其他人那里下载一个已经做好的镜像来直接使用。

容器(Container)

Docker 利用容器来运行应用。

容器是从镜像创建的运行实例。它可以被启动、开始、停止、删除。每个容器都是相互隔离的、保证安全的平台。

可以把容器看做是一个简易版的 Linux 环境(包括root用户权限、进程空间、用户空间和网络空间等)和运行在其中的应用程序。

仓库(Repository)

仓库是集中存放镜像文件的场所。有时候会把仓库和仓库注册服务器(Registry)混为一谈,并不严格区分。实际上,仓库注册服务器上往往存放着多个仓库,每个仓库中又包含了多个镜像,每个镜像有不同的标签(tag)。

仓库分为公开仓库(Public)和私有仓库(Private)两种形式。

最大的公开仓库是 Docker Hub,存放了数量庞大的镜像供用户下载。 国内的公开仓库包括 Docker Pool等,可以提供大陆用户更稳定快速的访问。

当然,用户也可以在本地网络内创建一个私有仓库。

当用户创建了自己的镜像之后就可以使用 push 命令将它上传到公有或者私有仓库,这样下次在另外一台机器上使用这个镜像时候,只需要从仓库上 pull 下来就可以了。

安装docker

1. 在yum repository增加docker的repository

# sudo vim /etc/yum.repos.d/docker.repo ## 在vim编辑器中输入以下内容后保存 [dockerrepo] 第4页

name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/ enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg 部公开▲

2. 安装docker-engine

yum install lvm2 yum install docker-engine

重新安装的话需需要删除docker的配置和数据目录,否则会有垃圾数据 rm -rf /usr/bin/docker rm -rf /var/lib/docker [root@localhost /]# ps aux|grep docker root 6779 0.0 0.0 112656 972 pts/2 S+ 11:04 0:00 grep --color=auto docker [root@localhost /]# service docker start Redirecting to /bin/systemctl start docker.service [root@localhost yum.repos.d]# ps aux|grep docker root 13376 1.2 0.0 2358880 45140 ? Ssl 09:47 0:17 /usr/bin/docker daemon -H fd:// root 13386 0.0 0.0 426968 10344 ? Ssl 09:47 0:00 docker-containerd -l /var/run/docker/libcontainerd/docker-containerd.sock --runtime docker-runc --start-timeout 2m root 15579 0.0 0.0 112660 972 pts/2 S+ 10:09 0:00 grep --color=auto docker 3. 测试docker服务是否成功

[root@localhost docker]# sudo 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 \ 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

第5页

部公开▲

Share images, automate workflows, and more with a free Docker Hub account: https://hub.docker.com For more examples and ideas, visit: https://docs.docker.com/engine/userguide/

下载镜像文件

[root@localhost yum.repos.d]# sudo docker pull ubuntu Using default tag: latest latest: Pulling from library/ubuntu f069f1d21059: Pull complete ecbeec5633cf: Pull complete ea6f18256d63: Pull complete 54bde7b02897: Pull complete Digest: sha256:bbfd93a02a8487edb60f20316ebc966ddc7aa123c2e609185450b96971020097 Status: Downloaded newer image for ubuntu:latest [root@localhost docker]# sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest c54a2cc56cbb 3 days ago 1.848 kB ubuntu latest 0f192147631d 5 days ago 132.7 MB [root@localhost docker]# sudo docker run ubuntu echo 'hello,I am here!' hello,I am here!

镜像

创建镜像的方法有3种:基于已有的镜像的容器创建、基于本地模板导入、基于dockerfile创建。

1. 基于已有镜像文件创建

[root@localhost ~]# sudo docker run -ti ubuntu:latest /bin/bash root@d34dce20aab5:/# pwd / root@d34dce20aab5:/# cd home/ root@d34dce20aab5:/home# ls root@d34dce20aab5:/home# mkdir setup root@d34dce20aab5:/home# touch test root@d34dce20aab5:/home# ls setup test root@d34dce20aab5:/home# exit exit 第6页

部公开▲

[root@localhost ~]# sudo docker commit -m \pyj_test sha256:fb1cc943194c47542636ef8d8072008a67656c5cd86354a07e9f95d1618a6295 上面代码,用-m指定行创建的镜像的提交信息。--author指定镜像作者,接着是容器ID、目标镜像仓库、镜像名。

2. 基于本地模板导入

可以从已有的一个系统上打包镜像,然后倒入docker [root@localhost ~]# sudo cat suse11sp3_python.tar.gz| docker import - suse11sp3_python sha256:d4e683d052ff8e29a7826e8bab468940f0b734666e66a7589e858813a7444047 3. 基于dockerfile创建

使用 docker commit 来扩展一个镜像比较简单,但是不方便在一个团队中分享。我们可以使用 dockerbuild 来创建一个新的镜像。为此,首先需要创建一个 Dockerfile,包含一些如何创建镜像的指令。

[root@host-192-168-101-222 home]# mkdir dockerfile [root@host-192-168-101-222 home]# cd dockerfile/ [root@host-192-168-101-222 dockerfile]# vi Dockerfile # This is a comment FROM 80.80.44.211:5000/ubuntu MAINTAINER Docker Newbee RUN echo \RUN mkdir -p /var/run/sshd [root@host-192-168-101-222 dockerfile]# sudo docker build -t=\ Sending build context to Docker daemon 2.048 kB Step 1 : FROM 80.80.44.211:5000/ubuntu ---> cf62323fa025 Step 2 : MAINTAINER Docker Newbee ---> Running in 0f1f3c470893 ---> 26b18e183480 Removing intermediate container 0f1f3c470893 Step 3 : RUN echo \ ---> Running in e04c0dd36f43 ---> bbcfab81ceda Removing intermediate container e04c0dd36f43 Step 4 : RUN mkdir -p /var/run/sshd ---> Running in 689d9cb5e730 ---> 67220c342e04 Removing intermediate container 689d9cb5e730 Successfully built 67220c342e04

第7页

部公开▲

[root@host-192-168-101-222 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE test/dockerfile v2 67220c342e04 5 seconds ago 124.9 MB

Dockerfile 基本的语法是: ? 使用 # 来注释

? FROM 指令告诉 Docker 使用哪个镜像作为基础 ? 接着是维护者的信息

? RUN 开头的指令会在创建中运行,比如安装一个软件包,在这里使用 apt-get 来安装

了一些软件

? ADD 命令复制本地文件到镜像; ? EXPOSE 命令来向外部开放端口;

? CMD 命令来描述容器启动后运行的程序等。

4. 存出和载入

如果要导出镜像到本地文件,可以使用 docker save 命令。 [root@localhost home]# sudo docker save -o ubutu_14.04.tar ubuntu:latest [root@localhost home]# ls suse11sp3_python.tar.gz suse11.tar ubutu_14.04.tar whc zte 可以使用 docker load 从导出的本地文件中再导入到本地镜像库。 [root@localhost home]# sudo docker load --input ubutu_14.04.tar [root@localhost home]# sudo docker load < ubuntu_14.04.tar

5. 镜像删除

docker rmi移除镜像文件,docker rm 是移除容器。 [root@localhost ~]# sudo docker rmi ubuntu:14.04 Untagged: ubuntu:14.04 Deleted: sha256:38c759202e30c0d088367425a0252634c3b401e77d547d16ea25d2af6836224d Deleted: sha256:566559fcd74db1fcfa4a505f95f3a97c16041aaa90b9375ebeda1a96eafc7cd7 Deleted: sha256:75afcfb9db7c7ac18deb72f222351ad401035950ee0bed913b7a64b341d27c21 Deleted: sha256:396597a0c01b802fbe1de93f3f070bd1b2f408df38f43ccc1f89b7da6e966fcc Deleted: sha256:81a9ec52d927ef3bf2d3959adbb104cdb6b0a925e7f1587579501bb3c35ace2f 如果镜像正在被容器占用,需要关闭容器,才能删除镜像,即使容器处于Exited状态。 [root@localhost ~]# sudo docker rmi ubuntu:14.04 Error response from daemon: conflict: unable to remove repository reference \

第8页

部公开▲

(must force) - container e1fcd0517b7e is using its referenced image 38c759202e30 [root@localhost ~]# docker ps -a|grep \ dfa7c09386a5 suse11sp3_python \ 6 Exited (0) 6 days ago condescending_lichterman 421b5b4ee59a suse11sp3_python \ 6 Exited (0) 6 days ago suspicious_banach e1fcd0517b7e ubuntu:14.04 \ 7 Exited (0) 7 days ago nauseous_sammet d788422ea8b3 ubuntu \'hello,I am her\ 7 Exited (0) 7 days ago goofy_brahmagupta bb98c37f066d hello-world \ 7 Exited (0) 7 days ago reverent_williams 5fdfab6a86cf hello-world \ 7 Exited (0) 7 days ago berserk_northcutt [root@localhost ~]# docker stop e1fcd0517b7e e1fcd0517b7e 批量删除镜像命令 [root@localhost ~]# docker rmi -f $(docker images -q -a ) 批量删除容器命令

[root@localhost ~]# docker ps -a|grep \dfa7c09386a5 421b5b4ee59a e1fcd0517b7e d788422ea8b3 bb98c37f066d 5fdfab6a86cf [root@localhost ~]# docker ps -a|grep \dfa7c09386a5 421b5b4ee59a e1fcd0517b7e d788422ea8b3 bb98c37f066d 5fdfab6a86cf [root@localhost ~]# sudo docker rmi ubuntu:14.04 Untagged: ubuntu:14.04 days ago days ago days ago days ago days ago days ago

容器

启动容器有两种方式,一种是基于镜像新建一个容器并启动,另外一个是将在终止状态(stopped)的容器重新启动。

第9页

部公开▲

1. 基于镜像新建一个容器并启动

[root@localhost home]# sudo docker run ubuntu /bin/echo 'Hello world' Hello world

如果镜像不存在,会自动去注册服务器下载对应的版本

[root@localhost home]# sudo docker run ubuntu:14.04 /bin/echo 'Hello world' Unable to find image 'ubuntu:14.04' locally 14.04: Pulling from library/ubuntu 96c6a1f3c3b0: Pull complete 4767a2d70a73: Pull complete 422639bc8a94: Pull complete a797489a324a: Pull complete Digest: sha256:b2c8a4d46473ab082200880391ddf8c06f2a67da4fa905ce2747dcd95d8d7af7 Status: Downloaded newer image for ubuntu:14.04 Hello world

-t选项让Docker分配一个伪终端(pseudo-tty)并绑定到容器的标准输入上, -i 则让容器的标准输入保持打开。 [root@localhost ~]# sudo docker run -ti suse11sp3_python /bin/bash 523b9a3bf923:/ # python Python 2.7.9 (default, Jun 8 2015, 10:12:06) [GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux2 Type \>>> 当利用 docker run 来创建容器时,Docker 在后台运行的标准操作包括: ? 检查本地是否存在指定的镜像,不存在就从公有仓库下载 ? 利用镜像创建并启动一个容器

? 分配一个文件系统,并在只读的镜像层外面挂载一层可读写层 ? 从宿主主机配置的网桥接口中桥接一个虚拟接口到容器中去 ? 从地址池配置一个 ip 地址给容器 ? 执行用户指定的应用程序 ? 执行完毕后容器被终止

2. 将在终止状态(stopped)的容器重新启动

用start命令打开一个停止的容器 [root@localhost ~]# sudo docker start cfe66bdec22d cfe66bdec22d 第10页

部公开▲

3. 守护态运行

-d 参数 ,-d参数表示docker把容器放到后台运行

[root@localhost ~]# sudo docker run -d ubuntu /bin/sh -c \1; done\ a5d0522d8740f045434c0ac877efd92818121387b4758a120cb3cc8ea9d2e23c [root@localhost ~]# sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a5d0522d8740 ubuntu \ 2 minutes ago Up 2 minutes angry_rosalind [root@localhost ~]# sudo docker logs a5d0522d8740 hello world hello world hello world hello world …

4. 进入容器

某些时候需要进入容器进行操作,有很多种方法,包括使用docker attach 命令或 nsenter 工具等。

[root@localhost ~]# sudo docker run -idt 80.80.44.211:5000/ubuntu [root@localhost ~]# sudo docker attach 15b5f564fb20 root@15b5f564fb20:/# [root@ localhost ~]# sudo docker attach 15b5f564fb20 You cannot attach to a stopped container, start it first

但是使用 attach 命令有时候并不方便。当多个窗口同时 attach 到同一个容器的时候,所有窗口都会同步显示。当某个窗口因命令阻塞时,其他窗口也无法执行操作了。

建议大家下载 .bashrc_docker,并将内容放到 .bashrc 中。

wget -P ~ https://github.com/yeasy/docker_practice/raw/master/_local/.bashrc_docker echo \ [root@ localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7059f20c3857 80.80.44.211:5000/ubuntu \ Up 29 seconds berserk_lamarr afc856f98918 registry:2.3.0 \/etc/d\minutes ago Up 17 minutes 0.0.0.0:5000->5000/tcp registry [root@ localhost ~]# docker-pid 7059f20c3857 第11页

8729 [root@host-192-168-101-222 ~]# docker-enter 7059f20c3857 root@7059f20c3857:~#

部公开▲

5. 终止

用stop命令打开一个停止的容器

[root@localhost ~]# sudo docker stop a5d0522d8740 a5d0522d8740

当Docker容器中指定的应用终结时,容器也自动终止。 例如对于上一章节中只启动了一个终端的容器,用户通过 exit 命令或 Ctrl+d 来退出终端时,所创建的容器立刻终止。

[root@localhost ~]# docker rm $(docker ps -a -q) docker rm命令遇到正在运行的容器就会失效,所以这个命令完美的删除了所有没在运行的容器。

6. 导出和导入容器

如果要导出本地某个容器,可以使用 docker export 命令。 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2c8395d13b58 registry \ 2 hours ago Up 2 hours 0.0.0.0:5000->5000/tcp gigantic_pare [root@localhost templates]# sudo docker export 2c8395d13b58 > registry.tar

可以使用 docker import 从容器快照文件中再导入为镜像

[root@localhost templates]# sudo cat registry.tar |docker import - test/registry:2.3.0 sha256:55d8f6a9f7d863c49aaaf8395b6933090fcc8af1c979332a4e7d2e1a483020ce

用户既可以使用 docker load 来导入镜像存储文件到本地镜像库,也可以使用 docker import 来导入一个容器快照到本地镜像库。这两者的区别在于容器快照文件将丢弃所有的历史记录和元数据信息(即仅保存容器当时的快照状态),而镜像存储文件将保存完整记录,体积也要大。此外,从容器快照文件导入时可以重新指定标签等元数据信息。

第12页

部公开▲

仓库

1. Docker HUB

仓库(Repository)是集中存放镜像的地方。

一个容易混淆的概念是注册服务器(Registry)。实际上注册服务器是管理仓库的具体服务器,每个服务器上可以有多个仓库,而每个仓库下面有多个镜像。从这方面来说,仓库可以被认为是一个具体的项目或目录。例如对于仓库地址dl.dockerpool.com/ubuntu来说, dl.dockerpool.com 是注册服务器地址, ubuntu 是仓库名。 [root@localhost ~]# sudo docker search ubuntu NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating s... 4281 [OK] ubuntu-upstart Upstart is an event-based replacement for ... 65 [OK] rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of... 29 [OK] torusware/speedus-ubuntu Always updated official Ubuntu docker imag... 26 [OK] …….

根据是否是官方提供,可将镜像资源分为两类。 一种是类似 centos 这样的基础镜像,被称为基础或根镜像。这些基础镜像是由 Docker 公司创建、验证、支持、提供。这样的镜像往往使用单个单词作为名字。还有一种类型,比如 tianon/centos 镜像,它是由 Docker 的用户创建并维护的,往往带有用户名称前缀。可以通过前缀 user_name/ 来指定使用某个用户提供的镜像,比如 tianon 用户。

可以通过docker pull命令将镜像下载到本地,用户也可以在登录后通过 docker push 命令来将镜像推送到 Docker Hub。

2. 私有仓库

docker-registry 是官方提供的工具,可以用于构建私有的镜像仓库。 yum install docker-registry

第13页

1、 构建私有仓库

部公开▲

[root@localhost]# sudo docker run -p 5000:5000 -v /home/registry/:/var/lib/registry -d registry:2.3.0 Unable to find image 'registry:2.3.0' locally Pulling repository docker.io/library/registry 1986f6fa547f: Pull complete d8bd0657b25f: Pull complete a582cd499e0f: Pull complete ff9c2740a9ad: Pull complete 598cf69db3df: Pull complete c3ee0ca45b37: Pull complete 1b808dcd3222: Pull complete 79dae8a48c0b: Pull complete b1029e55dfd2: Pull complete Status: Downloaded newer image for registry:2.3.0 docker.io/library/registry: this image was pulled from a legacy registry. Important: This registry version will not be supported in future versions of docker. daee588e4d3e7f15198d6891d4b4f27ad2406484bd51434a4ed461fc8c7fa05d [root@localhost ~]# docker tag registry:2.3.0 registry:latest [root@localhost ~]# sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES daee588e4d3e registry:2.3.0 \ 32 seconds ago Up 30 seconds 0.0.0.0:5000->5000/tcp furious_franklin 运行上述命令后,会从DockerHub上拉取registry镜像并在本地启动Registry服务,并监听5000端口。 [root@localhost ~]# curl 127.0.0.1:5000 \

2、重新标记一个本地镜像为私有仓库的版本,这里将本地的ubuntu标记为80.80.44.211:5000/ubuntu [root@localhost ~]# sudo docker tag ubuntu 80.80.44.211:5000/ubuntu [root@localhost ~]# sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE 80.80.44.211:5000/ubuntu latest cf62323fa025 9 days ago 124.9 MB ubuntu latest cf62323fa025 9 days ago 124.9 MB registry 2.3.0 36aac1e0ec3c 4 months ago 165.7 MB registry latest 36aac1e0ec3c 4 months ago 165.7 MB 3、再次查看镜像可以看到多了一个标记为80.80.44.211:5000/ubuntu的镜像,将本地镜像推送到本地仓库中。 [root@localhost home]# sudo docker push 80.80.44.211:5000/ubuntu The push refers to a repository [80.80.44.211:5000/ubuntu] eb33f051084b: Pushed

第14页

部公开▲

3e907de58acd: Pushed b04095771c04: Pushed 3d865816fc94: Pushed latest: digest: sha256:ba1688fec34f66d8a7ff5b42e6971625d8232c72bf0e38ad06dda10cad157293 size: 1130 [root@localhost ~]# curl http://80.80.44.211:5000/v2/_catalog {\ 可能会出现无法push镜像到私有仓库的问题 [root@localhost repositories]# sudo docker push 80.80.44.211:5000/suse11sp3_python The push refers to a repository [80.80.44.211:5000/suse11sp3_python] Get https://80.80.44.211:5000/v1/_ping: tls: oversized record received with length 20527

这是因为我们启动的registry服务不是安全可信赖的。这是我们需要修改docker的配置文件/etc/default/docker,添加下面的内DOCKER_OPTS=\,xxx.xxx.xxx.xxx:5000为私有仓库的地址。

[root@localhost etc]# vi /etc/sysconfig/docker INSECURE_REGISTRY=\OPTIONS=\[root@localhost etc]# systemctl restart docker

cat /usr/lib/systemd/system/docker.service [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network.target docker.socket Requires=docker.socket [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker MountFlags=slave LimitNOFILE=1048576 LimitNPROC=1048576 LimitCORE=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes EnvironmentFile=-/etc/sysconfig/docker EnvironmentFile=-/etc/sysconfig/docker-storage

第15页

EnvironmentFile=-/etc/sysconfig/docker-network ExecStart= ExecStart=/usr/bin/docker daemon -H fd:// $OPTIONS \\ $DOCKER_STORAGE_OPTIONS \\ $DOCKER_NETWORK_OPTIONS \\ $BLOCK_REGISTRY \\ $INSECURE_REGISTRY [Install] WantedBy=multi-user.target

删除现有的Ubuntu镜像,从80.80.44.211:5000/ ubuntu下拉成功 部公开▲

[root@host-192-168-101-222 ~]# docker rmi 80.80.44.211:5000/ubuntu [root@host-192-168-101-222 ~]# docker rmi ubuntu [root@host-192-168-101-222 ~]# docker pull 80.80.44.211:5000/ubuntu Using default tag: latest latest: Pulling from ubuntu 90d6565b970a: Pull complete 40553bdb8474: Pull complete c3129e7479ab: Pull complete 091663bd70db: Pull complete Digest: sha256:ba1688fec34f66d8a7ff5b42e6971625d8232c72bf0e38ad06dda10cad157293 Status: Downloaded newer image for 80.80.44.211:5000/ubuntu:latest

第16页

EnvironmentFile=-/etc/sysconfig/docker-network ExecStart= ExecStart=/usr/bin/docker daemon -H fd:// $OPTIONS \\ $DOCKER_STORAGE_OPTIONS \\ $DOCKER_NETWORK_OPTIONS \\ $BLOCK_REGISTRY \\ $INSECURE_REGISTRY [Install] WantedBy=multi-user.target

删除现有的Ubuntu镜像,从80.80.44.211:5000/ ubuntu下拉成功 部公开▲

[root@host-192-168-101-222 ~]# docker rmi 80.80.44.211:5000/ubuntu [root@host-192-168-101-222 ~]# docker rmi ubuntu [root@host-192-168-101-222 ~]# docker pull 80.80.44.211:5000/ubuntu Using default tag: latest latest: Pulling from ubuntu 90d6565b970a: Pull complete 40553bdb8474: Pull complete c3129e7479ab: Pull complete 091663bd70db: Pull complete Digest: sha256:ba1688fec34f66d8a7ff5b42e6971625d8232c72bf0e38ad06dda10cad157293 Status: Downloaded newer image for 80.80.44.211:5000/ubuntu:latest

第16页

本文来源:https://www.bwwdw.com/article/lsgo.html

Top