资讯专栏INFORMATION COLUMN

SpringCloud(第 052 篇)CentOS7 安装 Docker 以及常用操作命令讲解

jubincn / 3216人阅读

摘要:第篇安装以及常用操作命令讲解一大致介绍本章节主要带入大家初步进入,体验一下的安装步骤以及操作命令。

SpringCloud(第 052 篇)CentOS7 安装 Docker 以及常用操作命令讲解

-

一、大致介绍

</>复制代码

  1. 本章节主要带入大家初步进入 Docker,体验一下docker的安装步骤以及操作命令。
二、安装步骤 2.1 Docker环境部署要求

</>复制代码

  1. 1、Docker 需要运行在 64-bit 的操作系统上并且要求Linux 内核版本不小于 3.10,OS7满足这个要求;
  2. 2、其余低版本的可以使用yum update 命令对操作系统内核进行升级!
  3. 3、系统内核版本查看命令:uname -r
  4. [root@svr01 ~]# uname -r
  5. 3.10.0-514.6.2.el7.x86_64
2.2 yum 命令安装 Docker

</>复制代码

  1. [root@svr01 ~]# yum -y install docker
  2. 安装完了会看到如下的打印信息:
  3. Installed:
  4. docker.x86_64 2:1.12.6-68.gitec8512b.el7.centos
  5. Dependency Installed:
  6. audit-libs-python.x86_64 0:2.7.6-3.el7 checkpolicy.x86_64 0:2.5-4.el7
  7. container-selinux.noarch 2:2.33-1.git86f33cd.el7 container-storage-setup.noarch 0:0.8.0-3.git1d27ecf.el7
  8. device-mapper-event.x86_64 7:1.02.140-8.el7 device-mapper-event-libs.x86_64 7:1.02.140-8.el7
  9. device-mapper-persistent-data.x86_64 0:0.7.0-0.1.rc6.el7 docker-client.x86_64 2:1.12.6-68.gitec8512b.el7.centos
  10. docker-common.x86_64 2:1.12.6-68.gitec8512b.el7.centos libcgroup.x86_64 0:0.41-13.el7
  11. libseccomp.x86_64 0:2.3.1-3.el7 libsemanage-python.x86_64 0:2.5-8.el7
  12. lvm2.x86_64 7:2.02.171-8.el7 lvm2-libs.x86_64 7:2.02.171-8.el7
  13. oci-register-machine.x86_64 1:0-3.13.gitcd1e331.el7 oci-systemd-hook.x86_64 1:0.1.14-1.git1ba44c6.el7
  14. oci-umount.x86_64 2:2.3.0-1.git51e7c50.el7 policycoreutils-python.x86_64 0:2.5-17.1.el7
  15. python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-1.1.el7
  16. skopeo-containers.x86_64 1:0.1.26-2.dev.git2e8377a.el7.centos yajl.x86_64 0:2.0.4-4.el7
  17. Dependency Updated:
  18. audit.x86_64 0:2.7.6-3.el7 audit-libs.x86_64 0:2.7.6-3.el7 device-mapper.x86_64 7:1.02.140-8.el7
  19. device-mapper-libs.x86_64 7:1.02.140-8.el7 libsemanage.x86_64 0:2.5-8.el7 policycoreutils.x86_64 0:2.5-17.1.el7
  20. Complete!
2.3 检测 Docker 是否安装成功

</>复制代码

  1. [root@svr01 ~]# docker images
  2. Cannot connect to the Docker daemon. Is the docker daemon running on this host?
  3. 打印该信息说明docker已经安装了,只是没有启动docker而已;
2.4 启动 docker 后台服务

</>复制代码

  1. [root@svr01 ~]# service docker start
  2. Redirecting to /bin/systemctl start docker.service
2.5 查看 docker 的一些相关信息

</>复制代码

  1. 1、查看镜像列表
  2. [root@svr01 ~]# docker images
  3. REPOSITORY TAG IMAGE ID CREATED SIZE
  4. 2、查看运行的镜像列表
  5. [root@svr01 ~]# docker ps
  6. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2.6 测试下载 hello-world 镜像,本地没有的话则会从docker.io的远端镜像库下载

</>复制代码

  1. 1、下载 hello-world 镜像
  2. [root@svr01 ~]# docker run hello-world
  3. Unable to find image "hello-world:latest" locally
  4. Trying to pull repository docker.io/library/hello-world ...
  5. latest: Pulling from docker.io/library/hello-world
  6. ca4f61b1923c: Pull complete
  7. Digest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
  8. Hello from Docker!
  9. This message shows that your installation appears to be working correctly.
  10. To generate this message, Docker took the following steps:
  11. 1. The Docker client contacted the Docker daemon.
  12. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  13. (amd64)
  14. 3. The Docker daemon created a new container from that image which runs the
  15. executable that produces the output you are currently reading.
  16. 4. The Docker daemon streamed that output to the Docker client, which sent it
  17. to your terminal.
  18. To try something more ambitious, you can run an Ubuntu container with:
  19. $ docker run -it ubuntu bash
  20. Share images, automate workflows, and more with a free Docker ID:
  21. https://cloud.docker.com/
  22. For more examples and ideas, visit:
  23. https://docs.docker.com/engine/userguide/
  24. 2、再次查看 docker 现有的资源:
  25. [root@svr01 ~]# docker images
  26. REPOSITORY TAG IMAGE ID CREATED SIZE
  27. docker.io/hello-world latest f2a91732366c 3 weeks ago 1.848 kB
  28. [root@svr01 ~]# docker ps
  29. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2.7 搜索镜像文件

</>复制代码

  1. [root@svr01 ~]# docker search centos
  2. INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
  3. docker.io docker.io/centos The official build of CentOS. 3876 [OK]
  4. docker.io docker.io/ansible/centos7-ansible Ansible on Centos7 103 [OK]
  5. docker.io docker.io/jdeathe/centos-ssh CentOS-6 6.9 x86_64 / CentOS-7 7.4.1708 x8... 90 [OK]
  6. docker.io docker.io/consol/centos-xfce-vnc Centos container with "headless" VNC sessi... 37 [OK]
  7. docker.io docker.io/imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 34 [OK]
  8. docker.io docker.io/tutum/centos Simple CentOS docker image with SSH access 34
  9. docker.io docker.io/gluster/gluster-centos Official GlusterFS Image [ CentOS-7 + Glu... 21 [OK]
  10. docker.io docker.io/kinogmt/centos-ssh CentOS with SSH 17 [OK]
  11. docker.io docker.io/centos/python-35-centos7 Platform for building and running Python 3... 14
  12. docker.io docker.io/openshift/base-centos7 A Centos7 derived base image for Source-To... 13
  13. docker.io docker.io/centos/php-56-centos7 Platform for building and running PHP 5.6 ... 10
  14. docker.io docker.io/openshift/jenkins-2-centos7 A Centos7 based Jenkins v2.x image for use... 7
  15. docker.io docker.io/openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 ima... 6
  16. docker.io docker.io/darksheer/centos Base Centos Image -- Updated hourly 3 [OK]
  17. docker.io docker.io/openshift/ruby-20-centos7 DEPRECATED: A Centos7 based Ruby v2.0 imag... 3
  18. docker.io docker.io/blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK]
  19. docker.io docker.io/miko2u/centos6 CentOS6 鏃ユ湰瑾炵挵澧 1 [OK]
  20. docker.io docker.io/openshift/php-55-centos7 DEPRECATED: A Centos7 based PHP v5.5 image... 1
  21. docker.io docker.io/pivotaldata/centos-gpdb-dev CentOS image for GPDB development. Tag nam... 1
  22. docker.io docker.io/pivotaldata/centos-mingw Using the mingw toolchain to cross-compile... 1
  23. docker.io docker.io/jameseckersall/sonarr-centos Sonarr on CentOS 7 0 [OK]
  24. docker.io docker.io/openshift/wildfly-101-centos7 A Centos7 based WildFly v10.1 image for us... 0
  25. docker.io docker.io/pivotaldata/centos Base centos, freshened up a little with a ... 0
  26. docker.io docker.io/pivotaldata/centos-gcc-toolchain CentOS with a toolchain, but unaffiliated ... 0
  27. docker.io docker.io/smartentry/centos centos with smartentry 0 [OK]
2.8 拉取镜像文件

</>复制代码

  1. [root@svr01 ~]# docker pull docker.io/centos
2.9 运行刚刚下载的 docker.io/centos 镜像

</>复制代码

  1. [root@svr01 ~]# docker run -i -t docker.io/centos /bin/bash
  2. [root@9f053696bedb /]#
  3. 1、运行 docker run 命令后会看到已经进入的镜像文件内部,因此会看到 [root@9f053696bedb /]# 这样的命令展示信息。
  4. 2、进入镜像随便使用看看
  5. [root@9f053696bedb /]# ls
  6. anaconda-post.log bin dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
  7. [root@9f053696bedb /]# cd /home/
  8. [root@9f053696bedb home]# mkdir hmilyylimh
  9. [root@9f053696bedb home]# mkdir -p hmilyylimh/docker
  10. [root@9f053696bedb home]# cd hmilyylimh/docker/
  11. [root@9f053696bedb docker]#
  12. 3、退出镜像
  13. [root@9f053696bedb docker]# exit
  14. exit
  15. [root@svr01 ~]#
  16. 4、参数说明:
  17. -a stdin: 指定标准输入输出内容类型,可选 STDIN/STDOUT/STDERR 三项;
  18. -d: 后台运行容器,并返回容器ID;
  19. -i: 以交互模式运行容器,通常与 -t 同时使用;
  20. -t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
  21. --name="nginx-lb": 为容器指定一个名称;
  22. --dns 8.8.8.8: 指定容器使用的DNS服务器,默认和宿主一致;
  23. --dns-search example.com: 指定容器DNS搜索域名,默认和宿主一致;
  24. -h "mars": 指定容器的hostname;
  25. -e username="ritchie": 设置环境变量;
  26. --env-file=[]: 从指定文件读入环境变量;
  27. --cpuset="0-2" or --cpuset="0,1,2": 绑定容器到指定CPU运行;
  28. -m :设置容器使用内存最大值;
  29. --net="bridge": 指定容器的网络连接类型,支持 bridge/host/none/container: 四种类型;
  30. --link=[]: 添加链接到另一个容器;
  31. --expose=[]: 开放一个端口或一组端口;
2.10 在 docker.io/centos 镜像中随便装个东西,举例装个json

</>复制代码

  1. [root@svr01 ~]# docker run -i -t docker.io/centos /bin/bash
  2. [root@497905f140a6 /]# gem install json
  3. bash: gem: command not found
  4. [root@497905f140a6 /]# yum install gem
  5. 。。。。
  6. Installed:
  7. rubygems.noarch 0:2.0.14.1-30.el7
  8. Dependency Installed:
  9. libyaml.x86_64 0:0.1.4-11.el7_0 ruby.x86_64 0:2.0.0.648-30.el7 ruby-irb.noarch 0:2.0.0.648-30.el7 ruby-libs.x86_64 0:2.0.0.648-30.el7
  10. rubygem-bigdecimal.x86_64 0:1.2.0-30.el7 rubygem-io-console.x86_64 0:0.4.2-30.el7 rubygem-json.x86_64 0:1.7.7-30.el7 rubygem-psych.x86_64 0:2.0.0-30.el7
  11. rubygem-rdoc.noarch 0:4.0.0-30.el7
  12. Complete!
  13. [root@497905f140a6 /]# gem install json
  14. Fetching: json-2.1.0.gem (100%)
  15. Building native extensions. This could take a while...
  16. ERROR: Error installing json:
  17. ERROR: Failed to build gem native extension.
  18. /usr/bin/ruby extconf.rb
  19. mkmf.rb can"t find header files for ruby at /usr/share/include/ruby.h
  20. Gem files will remain installed in /usr/local/share/gems/gems/json-2.1.0 for inspection.
  21. Results logged to /usr/local/share/gems/gems/json-2.1.0/ext/json/ext/generator/gem_make.out
2.11 针对已经安装json的docker.io/centos镜像库打包,tag命名为v2

</>复制代码

  1. [root@497905f140a6 /]# docker commit -m ="add new image" -a="hmilyylimh" 497905f140a6 docker.io/centos:v2
  2. bash: docker: command not found
  3. [root@497905f140a6 /]# exit
  4. exit
  5. [root@svr01 ~]# docker commit -m ="add new image" -a="HEHUI231" 497905f140a6 docker.io/centos:v2
  6. sha256:11efb35f320cec46c83bc4dcbc184c8d45dcb3e369105251d70e2336fd261c92
  7. [root@svr01 ~]# docker images;
  8. REPOSITORY TAG IMAGE ID CREATED SIZE
  9. docker.io/centos v2 11efb35f320c 17 seconds ago 307.5 MB
  10. docker.io/centos latest 3fa822599e10 2 weeks ago 203.5 MB
  11. docker.io/hello-world latest f2a91732366c 3 weeks ago 1.848 kB
2.12 给刚刚打包的 docker.io/centos:v2 镜像设置镜像标签

</>复制代码

  1. [root@svr01 ~]# docker tag 11efb35f320c docker.io/centos:v22
  2. [root@svr01 ~]# docker images;
  3. REPOSITORY TAG IMAGE ID CREATED SIZE
  4. docker.io/centos v2 11efb35f320c 36 minutes ago 307.5 MB
  5. docker.io/centos v22 11efb35f320c 36 minutes ago 307.5 MB
  6. docker.io/centos latest 3fa822599e10 2 weeks ago 203.5 MB
  7. docker.io/hello-world latest f2a91732366c 3 weeks ago 1.848 kB
2.13 删除 docker.io/centos:v2 镜像文件

</>复制代码

  1. [root@svr01 ~]# docker rmi docker.io/centos:v22
  2. Untagged: docker.io/centos:v22
  3. [root@svr01 ~]# docker images;
  4. REPOSITORY TAG IMAGE ID CREATED SIZE
  5. docker.io/centos v2 11efb35f320c 37 minutes ago 307.5 MB
  6. docker.io/centos latest 3fa822599e10 2 weeks ago 203.5 MB
  7. docker.io/hello-world latest f2a91732366c 3 weeks ago 1.848 kB
2.14 删除单个已经停止的容器

</>复制代码

  1. [root@svr01 ~]# docker rm 47de3399a0ab
  2. 47de3399a0ab
  3. [root@svr01 ~]# docker ps -l
  4. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2.15 删除所有已经停止的容器

</>复制代码

  1. [root@svr01 ~]# docker rm $(docker ps -a -q)
  2. ca94bd87299f
  3. 43a27d23f3ee
  4. 497905f140a6
  5. fb9512c00a84
  6. 9f053696bedb
  7. 565b5d3e5139
  8. 9c2518ba47c8
  9. 1abaaef82836
  10. e5b39fc724ab
  11. [root@svr01 ~]# docker ps -l
  12. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2.16 杀掉单个正在执行的容器

</>复制代码

  1. [root@svr01 ~]# docker kill 47de3399a0ab
  2. 47de3399a0ab
  3. [root@svr01 ~]# docker ps -l
  4. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2.17 杀掉所有正在执行的容器

</>复制代码

  1. [root@svr01 ~]# docker kill $(docker ps -q)
  2. ca94bd87299f
  3. 43a27d23f3ee
  4. 497905f140a6
  5. fb9512c00a84
  6. 9f053696bedb
  7. 565b5d3e5139
  8. 9c2518ba47c8
  9. 1abaaef82836
  10. e5b39fc724ab
  11. [root@svr01 ~]# docker ps -l
  12. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2.18 将image文件保存到磁盘目录

</>复制代码

  1. [root@svr01 ~]# docker images;
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. docker.io/centos v2 11efb35f320c 5 hours ago 307.5 MB
  4. docker.io/frolvlad/alpine-oraclejdk8 latest 4f03dc990224 12 days ago 170.1 MB
  5. docker.io/centos latest 3fa822599e10 2 weeks ago 203.5 MB
  6. docker.io/hello-world latest f2a91732366c 3 weeks ago 1.848 kB
  7. [root@svr01 ~]# docker save 4f03dc990224 > /home/install/alpine-oraclejdk8.tar
  8. [root@svr01 ~]# ls /home/install/
  9. alpine-oraclejdk8.tar hive MySQL-5.6.27-1.el7.x86_64.rpm-bundle.tar openssl-1.0.2l.tar.gz redis-3.2.9.tar.gz
  10. apache-flume-1.7.0-bin.tar.gz httpd-2.4.26.tar.gz mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar pcre-8.41.tar.gz zlib-1.2.11.tar.gz
  11. hadoop memcached-1.4.39.tar.gz nginx-1.12.0.tar.gz php-5.6.31.tar.gz zookeeper-3.4.10.tar.gz
2.19 将磁盘的镜像文件导入到docker中,并且通过 docker tag 修改名称和tag

</>复制代码

  1. [root@svr01 ~]# docker load < /home/install/centos-v2.tar
  2. e9613a472968: Loading layer [==================================================>] 105 MB/105 MB
  3. Loaded image ID: sha256:11efb35f320cec46c83bc4dcbc184c8d45dcb3e369105251d70e2336fd261c92
  4. [root@svr01 ~]# docker images
  5. REPOSITORY TAG IMAGE ID CREATED SIZE
  6. 11efb35f320c 5 hours ago 307.5 MB
  7. docker.io/frolvlad/alpine-oraclejdk8 latest 4f03dc990224 12 days ago 170.1 MB
  8. docker.io/centos latest 3fa822599e10 2 weeks ago 203.5 MB
  9. docker.io/hello-world latest f2a91732366c 3 weeks ago 1.848 kB
  10. [root@svr01 ~]# docker tag 11efb35f320c docker.io/centos:v2
  11. [root@svr01 ~]# docker images
  12. REPOSITORY TAG IMAGE ID CREATED SIZE
  13. docker.io/centos v2 11efb35f320c 5 hours ago 307.5 MB
  14. docker.io/frolvlad/alpine-oraclejdk8 latest 4f03dc990224 12 days ago 170.1 MB
  15. docker.io/centos latest 3fa822599e10 2 weeks ago 203.5 MB
  16. docker.io/hello-world latest f2a91732366c 3 weeks ago 1.848 kB
2.20 验证刚刚加载的镜像能否成功运行,能进入的话,并且成功exit则导入成功

</>复制代码

  1. [root@svr01 ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. docker.io/centos v2 11efb35f320c 5 hours ago 307.5 MB
  4. docker.io/frolvlad/alpine-oraclejdk8 latest 4f03dc990224 12 days ago 170.1 MB
  5. docker.io/centos latest 3fa822599e10 2 weeks ago 203.5 MB
  6. docker.io/hello-world latest f2a91732366c 3 weeks ago 1.848 kB
  7. [root@svr01 ~]# docker run -it docker.io/centos:v2
  8. [root@0a87728d1798 /]# ls
  9. anaconda-post.log bin dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
  10. [root@0a87728d1798 /]# exit
  11. exit
  12. [root@svr01 ~]#
三、下载地址

https://gitee.com/ylimhhmily/SpringCloudTutorial.git

SpringCloudTutorial交流QQ群: 235322432

SpringCloudTutorial交流微信群: 微信沟通群二维码图片链接

欢迎关注,您的肯定是对我最大的支持!!!

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/27159.html

相关文章

  • SpringCloud 052 CentOS7 安装 Docker 以及常用操作命令讲解

    摘要:第篇安装以及常用操作命令讲解一大致介绍本章节主要带入大家初步进入,体验一下的安装步骤以及操作命令。 SpringCloud(第 052 篇)CentOS7 安装 Docker 以及常用操作命令讲解 - 一、大致介绍 本章节主要带入大家初步进入 Docker,体验一下docker的安装步骤以及操作命令。 二、安装步骤 2.1 Docker环境部署要求 1、Docker 需要运行在 64-...

    suxier 评论0 收藏0
  • SpringCloud 053 CentOS7 中用 Docker 部署一个简单的基于 Eu

    摘要:第篇中用部署一个简单的基于服务治理发现的项目一大致介绍纠结了一下下,这么简单的部署流程是否需要详细的贴出来,然而纠结了一下还是将这个简单的部署流程补充完整了经过上节的讲解,相信大家已经对的命令操作都有了一定的了解,这里我就暂且默认大家都拥 SpringCloud(第 053 篇)CentOS7 中用 Docker 部署一个简单的基于 Eureka 服务治理发现的项目 - 一、大致介绍 ...

    mgckid 评论0 收藏0
  • SpringCloud 053 CentOS7 中用 Docker 部署一个简单的基于 Eu

    摘要:第篇中用部署一个简单的基于服务治理发现的项目一大致介绍纠结了一下下,这么简单的部署流程是否需要详细的贴出来,然而纠结了一下还是将这个简单的部署流程补充完整了经过上节的讲解,相信大家已经对的命令操作都有了一定的了解,这里我就暂且默认大家都拥 SpringCloud(第 053 篇)CentOS7 中用 Docker 部署一个简单的基于 Eureka 服务治理发现的项目 - 一、大致介绍 ...

    Enlightenment 评论0 收藏0
  • paascloud开源项目学习(2) -- centos7安装SpringCloud+Vue环境

    摘要:依次执行下面命令本地安装从官方安装包下载。管理界面提供多种管理方式命令行和界面等提供一个开源的扩展项目里面包含一个子项目配置下打个包就可以用了。 前言 github 开源项目--paascloud-master:https://github.com/paascloud/... paascloud-master 官方环境搭建:http://blog.paascloud.net/20...

    jsdt 评论0 收藏0
  • SpringCloud 055 CentOS7 搭建 docker-registry 私有库

    摘要:第篇搭建私有库及管理界面一大致介绍基于前面的部署,容器一多非常不便于管理,于是急需一个自己的私有库而目前市面上大多数的私有库基本上都是后台服务加前台构成,于是选来选去,最后选择了管理界面之所以选择这款管理界面,我就简述阐述一下,基于以下 SpringCloud(第 055 篇)CentOS7 搭建 docker-registry 私有库及管理界面 - 一、大致介绍 1、基于前面dock...

    tracymac7 评论0 收藏0

发表评论

0条评论

jubincn

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<