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

阅读:625 2019-03-19 14:44:24 来源:开源中国

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

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

[root@svr01~]#yum-yinstalldocker安装完了会看到如下的打印信息:installed:docker.x86_642:1.12.6-68.gitec8512b.el7.centosdependencyinstalled:audit-libs-python.x86_640:2.7.6-3.el7checkpolicy.x86_640:2.5-4.el7container-selinux.noarch2:2.33-1.git86f33cd.el7container-storage-setup.noarch0:0.8.0-3.git1d27ecf.el7device-mapper-event.x86_647:1.02.140-8.el7device-mapper-event-libs.x86_647:1.02.140-8.el7device-mapper-persistent-data.x86_640:0.7.0-0.1.rc6.el7docker-client.x86_642:1.12.6-68.gitec8512b.el7.centosdocker-common.x86_642:1.12.6-68.gitec8512b.el7.centoslibcgroup.x86_640:0.41-13.el7libseccomp.x86_640:2.3.1-3.el7libsemanage-python.x86_640:2.5-8.el7lvm2.x86_647:2.02.171-8.el7lvm2-libs.x86_647:2.02.171-8.el7oci-register-machine.x86_641:0-3.13.gitcd1e331.el7oci-systemd-hook.x86_641:0.1.14-1.git1ba44c6.el7oci-umount.x86_642:2.3.0-1.git51e7c50.el7policycoreutils-python.x86_640:2.5-17.1.el7python-ipy.noarch0:0.75-6.el7setools-libs.x86_640:3.3.8-1.1.el7skopeo-containers.x86_641:0.1.26-2.dev.git2e8377a.el7.centosyajl.x86_640:2.0.4-4.el7dependencyupdated:audit.x86_640:2.7.6-3.el7audit-libs.x86_640:2.7.6-3.el7device-mapper.x86_647:1.02.140-8.el7device-mapper-libs.x86_647:1.02.140-8.el7libsemanage.x86_640:2.5-8.el7policycoreutils.x86_640:2.5-17.1.el7complete!2.3检测docker是否安装成功

[root@svr01~]#dockerimagescannotconnecttothedockerdaemon.isthedockerdaemonrunningonthishost?打印该信息说明docker已经安装了,只是没有启动docker而已;2.4启动docker后台服务

[root@svr01~]#servicedockerstartredirectingto/bin/systemctlstartdocker.service2.5查看docker的一些相关信息

1、查看镜像列表[root@svr01~]#dockerimagesrepositorytagimageidcreatedsize2、查看运行的镜像列表[root@svr01~]#dockerpscontaineridimagecommandcreatedstatusportsnames2.6测试下载hello-world镜像,本地没有的话则会从docker.io的远端镜像库下载

1、下载hello-world镜像[root@svr01~]#dockerrunhello-worldunabletofindimage'hello-world:latest'locallytryingtopullrepositorydocker.io/library/hello-world...latest:pullingfromdocker.io/library/hello-worldca4f61b1923c:pullcompletedigest:sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905chellofromdocker!thismessageshowsthatyourinstallationappearstobeworkingcorrectly.togeneratethismessage,dockertookthefollowingsteps:1.thedockerclientcontactedthedockerdaemon.2.thedockerdaemonpulledthe"hello-world"imagefromthedockerhub.(amd64)3.thedockerdaemoncreatedanewcontainerfromthatimagewhichrunstheexecutablethatproducestheoutputyouarecurrentlyreading.4.thedockerdaemonstreamedthatoutputtothedockerclient,whichsentittoyourterminal.totrysomethingmoreambitious,youcanrunanubuntucontainerwith:$dockerrun-itubuntubashshareimages,automateworkflows,andmorewithafreedockerid:https://cloud.docker.com/formoreexamplesandideas,visit:https://docs.docker.com/engine/userguide/2、再次查看docker现有的资源:[root@svr01~]#dockerimagesrepositorytagimageidcreatedsizedocker.io/hello-worldlatestf2a91732366c3weeksago1.848kb[root@svr01~]#dockerpscontaineridimagecommandcreatedstatusportsnames2.7搜索镜像文件

[root@svr01~]#dockersearchcentosindexnamedescriptionstarsofficialautomateddocker.iodocker.io/centostheofficialbuildofcentos.3876[ok]docker.iodocker.io/ansible/centos7-ansibleansibleoncentos7103[ok]docker.iodocker.io/jdeathe/centos-sshcentos-66.9x86_64/centos-77.4.1708x8...90[ok]docker.iodocker.io/consol/centos-xfce-vnccentoscontainerwith"headless"vncsessi...37[ok]docker.iodocker.io/imagine10255/centos6-lnmp-php56centos6-lnmp-php5634[ok]docker.iodocker.io/tutum/centossimplecentosdockerimagewithsshaccess34docker.iodocker.io/gluster/gluster-centosofficialglusterfsimage[centos-7+glu...21[ok]docker.iodocker.io/kinogmt/centos-sshcentoswithssh17[ok]docker.iodocker.io/centos/python-35-centos7platformforbuildingandrunningpython3...14docker.iodocker.io/openshift/base-centos7acentos7derivedbaseimageforsource-to...13docker.iodocker.io/centos/php-56-centos7platformforbuildingandrunningphp5.6...10docker.iodocker.io/openshift/jenkins-2-centos7acentos7basedjenkinsv2.ximageforuse...7docker.iodocker.io/openshift/mysql-55-centos7deprecated:acentos7basedmysqlv5.5ima...6docker.iodocker.io/darksheer/centosbasecentosimage--updatedhourly3[ok]docker.iodocker.io/openshift/ruby-20-centos7deprecated:acentos7basedrubyv2.0imag...3docker.iodocker.io/blacklabelops/centoscentosbaseimage!builtandupdatesdaily!1[ok]docker.iodocker.io/miko2u/centos6centos6鏃ユ湰瑾炵挵澧1[ok]docker.iodocker.io/openshift/php-55-centos7deprecated:acentos7basedphpv5.5image...1docker.iodocker.io/pivotaldata/centos-gpdb-devcentosimageforgpdbdevelopment.tagnam...1docker.iodocker.io/pivotaldata/centos-mingwusingthemingwtoolchaintocross-compile...1docker.iodocker.io/jameseckersall/sonarr-centossonarroncentos70[ok]docker.iodocker.io/openshift/wildfly-101-centos7acentos7basedwildflyv10.1imageforus...0docker.iodocker.io/pivotaldata/centosbasecentos,freshenedupalittlewitha...0docker.iodocker.io/pivotaldata/centos-gcc-toolchaincentoswithatoolchain,butunaffiliated...0docker.iodocker.io/smartentry/centoscentoswithsmartentry0[ok]2.8拉取镜像文件

[root@svr01~]#dockerpulldocker.io/centos2.9运行刚刚下载的docker.io/centos镜像

[root@svr01~]#dockerrun-i-tdocker.io/centos/bin/bash[root@9f053696bedb/]#1、运行dockerrun命令后会看到已经进入的镜像文件内部,因此会看到[root@9f053696bedb/]#这样的命令展示信息。2、进入镜像随便使用看看[root@9f053696bedb/]#lsanaconda-post.logbindevetchomeliblib64mediamntoptprocrootrunsbinsrvsystmpusrvar[root@9f053696bedb/]#cd/home/[root@9f053696bedbhome]#mkdirhmilyylimh[root@9f053696bedbhome]#mkdir-phmilyylimh/docker[root@9f053696bedbhome]#cdhmilyylimh/docker/[root@9f053696bedbdocker]#3、退出镜像[root@9f053696bedbdocker]#exitexit[root@svr01~]#4、参数说明:-astdin:指定标准输入输出内容类型,可选stdin/stdout/stderr三项;-d:后台运行容器,并返回容器id;-i:以交互模式运行容器,通常与-t同时使用;-t:为容器重新分配一个伪输入终端,通常与-i同时使用;--name="nginx-lb":为容器指定一个名称;--dns8.8.8.8:指定容器使用的dns服务器,默认和宿主一致;--dns-searchexample.com:指定容器dns搜索域名,默认和宿主一致;-h"mars":指定容器的hostname;-eusername="ritchie":设置环境变量;--env-file=[]:从指定文件读入环境变量;--cpuset="0-2"or--cpuset="0,1,2":绑定容器到指定cpu运行;-m:设置容器使用内存最大值;--net="bridge":指定容器的网络连接类型,支持bridge/host/none/container:四种类型;--link=[]:添加链接到另一个容器;--expose=[]:开放一个端口或一组端口;2.10在docker.io/centos镜像中随便装个东西,举例装个json

[root@svr01~]#dockerrun-i-tdocker.io/centos/bin/bash[root@497905f140a6/]#geminstalljsonbash:gem:commandnotfound[root@497905f140a6/]#yuminstallgem。。。。installed:rubygems.noarch0:2.0.14.1-30.el7dependencyinstalled:libyaml.x86_640:0.1.4-11.el7_0ruby.x86_640:2.0.0.648-30.el7ruby-irb.noarch0:2.0.0.648-30.el7ruby-libs.x86_640:2.0.0.648-30.el7rubygem-bigdecimal.x86_640:1.2.0-30.el7rubygem-io-console.x86_640:0.4.2-30.el7rubygem-json.x86_640:1.7.7-30.el7rubygem-psych.x86_640:2.0.0-30.el7rubygem-rdoc.noarch0:4.0.0-30.el7complete![root@497905f140a6/]#geminstalljsonfetching:json-2.1.0.gem(100%)buildingnativeextensions.thiscouldtakeawhile...error:errorinstallingjson:error:failedtobuildgemnativeextension./usr/bin/rubyextconf.rbmkmf.rbcan'tfindheaderfilesforrubyat/usr/share/include/ruby.hgemfileswillremaininstalledin/usr/local/share/gems/gems/json-2.1.0forinspection.resultsloggedto/usr/local/share/gems/gems/json-2.1.0/ext/json/ext/generator/gem_make.out2.11针对已经安装json的docker.io/centos镜像库打包,tag命名为v2

[root@497905f140a6/]#dockercommit-m="addnewimage"-a="hmilyylimh"497905f140a6docker.io/centos:v2bash:docker:commandnotfound[root@497905f140a6/]#exitexit[root@svr01~]#dockercommit-m="addnewimage"-a="hehui231"497905f140a6docker.io/centos:v2sha256:11efb35f320cec46c83bc4dcbc184c8d45dcb3e369105251d70e2336fd261c92[root@svr01~]#dockerimages;repositorytagimageidcreatedsizedocker.io/centosv211efb35f320c17secondsago307.5mbdocker.io/centoslatest3fa822599e102weeksago203.5mbdocker.io/hello-worldlatestf2a91732366c3weeksago1.848kb2.12给刚刚打包的docker.io/centos:v2镜像设置镜像标签

[root@svr01~]#dockertag11efb35f320cdocker.io/centos:v22[root@svr01~]#dockerimages;repositorytagimageidcreatedsizedocker.io/centosv211efb35f320c36minutesago307.5mbdocker.io/centosv2211efb35f320c36minutesago307.5mbdocker.io/centoslatest3fa822599e102weeksago203.5mbdocker.io/hello-worldlatestf2a91732366c3weeksago1.848kb2.13删除docker.io/centos:v2镜像文件

[root@svr01~]#dockerrmidocker.io/centos:v22untagged:docker.io/centos:v22[root@svr01~]#dockerimages;repositorytagimageidcreatedsizedocker.io/centosv211efb35f320c37minutesago307.5mbdocker.io/centoslatest3fa822599e102weeksago203.5mbdocker.io/hello-worldlatestf2a91732366c3weeksago1.848kb2.14删除单个已经停止的容器

[root@svr01~]#dockerrm47de3399a0ab47de3399a0ab[root@svr01~]#dockerps-lcontaineridimagecommandcreatedstatusportsnames2.15删除所有已经停止的容器

[root@svr01~]#dockerrm$(dockerps-a-q)ca94bd87299f43a27d23f3ee497905f140a6fb9512c00a849f053696bedb565b5d3e51399c2518ba47c81abaaef82836e5b39fc724ab[root@svr01~]#dockerps-lcontaineridimagecommandcreatedstatusportsnames2.16杀掉单个正在执行的容器

[root@svr01~]#dockerkill47de3399a0ab47de3399a0ab[root@svr01~]#dockerps-lcontaineridimagecommandcreatedstatusportsnames2.17杀掉所有正在执行的容器

[root@svr01~]#dockerkill$(dockerps-q)ca94bd87299f43a27d23f3ee497905f140a6fb9512c00a849f053696bedb565b5d3e51399c2518ba47c81abaaef82836e5b39fc724ab[root@svr01~]#dockerps-lcontaineridimagecommandcreatedstatusportsnames2.18将image文件保存到磁盘目录

[root@svr01~]#dockerimages;repositorytagimageidcreatedsizedocker.io/centosv211efb35f320c5hoursago307.5mbdocker.io/frolvlad/alpine-oraclejdk8latest4f03dc99022412daysago170.1mbdocker.io/centoslatest3fa822599e102weeksago203.5mbdocker.io/hello-worldlatestf2a91732366c3weeksago1.848kb[root@svr01~]#dockersave4f03dc990224>/home/install/alpine-oraclejdk8.tar[root@svr01~]#ls/home/install/alpine-oraclejdk8.tarhivemysql-5.6.27-1.el7.x86_64.rpm-bundle.taropenssl-1.0.2l.tar.gzredis-3.2.9.tar.gzapache-flume-1.7.0-bin.tar.gzhttpd-2.4.26.tar.gzmysql-5.7.18-1.el7.x86_64.rpm-bundle.tarpcre-8.41.tar.gzzlib-1.2.11.tar.gzhadoopmemcached-1.4.39.tar.gznginx-1.12.0.tar.gzphp-5.6.31.tar.gzzookeeper-3.4.10.tar.gz2.19将磁盘的镜像文件导入到docker中,并且通过dockertag修改名称和tag

[root@svr01~]#dockerload]105mb/105mbloadedimageid:sha256:11efb35f320cec46c83bc4dcbc184c8d45dcb3e369105251d70e2336fd261c92[root@svr01~]#dockerimagesrepositorytagimageidcreatedsize11efb35f320c5hoursago307.5mbdocker.io/frolvlad/alpine-oraclejdk8latest4f03dc99022412daysago170.1mbdocker.io/centoslatest3fa822599e102weeksago203.5mbdocker.io/hello-worldlatestf2a91732366c3weeksago1.848kb[root@svr01~]#dockertag11efb35f320cdocker.io/centos:v2[root@svr01~]#dockerimagesrepositorytagimageidcreatedsizedocker.io/centosv211efb35f320c5hoursago307.5mbdocker.io/frolvlad/alpine-oraclejdk8latest4f03dc99022412daysago170.1mbdocker.io/centoslatest3fa822599e102weeksago203.5mbdocker.io/hello-worldlatestf2a91732366c3weeksago1.848kb2.20验证刚刚加载的镜像能否成功运行,能进入的话,并且成功exit则导入成功

[root@svr01~]#dockerimagesrepositorytagimageidcreatedsizedocker.io/centosv211efb35f320c5hoursago307.5mbdocker.io/frolvlad/alpine-oraclejdk8latest4f03dc99022412daysago170.1mbdocker.io/centoslatest3fa822599e102weeksago203.5mbdocker.io/hello-worldlatestf2a91732366c3weeksago1.848kb[root@svr01~]#dockerrun-itdocker.io/centos:v2[root@0a87728d1798/]#lsanaconda-post.logbindevetchomeliblib64mediamntoptprocrootrunsbinsrvsystmpusrvar[root@0a87728d1798/]#exitexit[root@svr01~]#三、下载地址

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

springcloudtutorial交流qq群:235322432

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

相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>
推荐商标

{{ v.name }}

{{ v.cls }}类

立即购买 联系客服