docker命令详解1/20docker[OPTIONS]commandUsage:docker[OPTIONS]COMMAND[arg...]dockerdaemon[--help|...]docker[-h|--help|-v|--version]Aself-sufficientruntimeforcontainers.Options:--config=~/.dockerLocationofclientconfigfiles-D,--debug=falseEnabledebugmode-H,--host=[]Daemonsocket(s)toconnectto-h,--help=falsePrintusage-l,--log-level=infoSetthelogginglevel--tls=falseUseTLS;impliedby--tlsverify--tlscacert=~/.docker/ca.pemTrustcertssignedonlybythisCA--tlscert=~/.docker/cert.pemPathtoTLScertificatefile--tlskey=~/.docker/key.pemPathtoTLSkeyfile--tlsverify=falseUseTLSandverifytheremote-v,--version=falsePrintversioninformationandquitattachAttachtoarunningcontainer将终端依附到容器上Usage:dockerattach[OPTIONS]CONTAINERAttachtoarunningcontainer--help=falsePrintusage--no-stdin=falseDonotattachSTDIN--sig-proxy=trueProxyallreceivedsignalstotheprocess为后端运行的交互式的容器启用一个终端与之交互。1.后台有一个可以交互的容器.docker命令详解2/202.启动该容器.3.通过attach启动终端与之交互buildUsage:dockerbuild[OPTIONS]PATH|URL|-BuildanimagefromaDockerfile--build-arg=[]Setbuild-timevariables--cpu-shares=0CPUshares(relativeweight)--cgroup-parent=Optionalparentcgroupforthecontainer--cpu-period=0LimittheCPUCFS(CompletelyFairScheduler)period--cpu-quota=0LimittheCPUCFS(CompletelyFairScheduler)quota--cpuset-cpus=CPUsinwhichtoallowexecution(0-3,0,1)--cpuset-mems=MEMsinwhichtoallowexecution(0-3,0,1)--disable-content-trust=trueSkipimageverification-f,--file=NameoftheDockerfile(Defaultis'PATH/Dockerfile')--force-rm=falseAlwaysremoveintermediatecontainers--help=falsePrintusage-m,--memory=Memorylimit--memory-swap=Totalmemory(memory+swap),'-1'todisableswap--no-cache=falseDonotusecachewhenbuildingtheimage--pull=falseAlwaysattempttopullanewerversionoftheimage-q,--quiet=falseSuppresstheverboseoutputgeneratedbythecontainers--rm=trueRemoveintermediatecontainersafterasuccessfulbuild-t,--tag=Repositoryname(andoptionallyatag)fortheimage--ulimit=[]Ulimitoptions通过Dockerfile创建镜像。具体见以后的使用中。commitUsage:dockercommit[OPTIONS]CONTAINER[REPOSITORY[:TAG]]Createanewimagefromacontainer'schanges-a,--author=Author(e.g.,JohnHannibalSmithhannibal@a-team.com)-c,--change=[]ApplyDockerfileinstructiontothecreatedimage--help=falsePrintusagedocker命令详解3/20-m,--message=Commitmessage-p,--pause=truePausecontainerduringcommit通过容器创建本地镜像.可自定义tag,如dockercommitdc806ee0bf86web:v1不指定tag的情况下默认tag为latestroot@ubuntu:~#dockercommitdc806ee0bf86test1e488386876e14ef3e930a98ec0bb49de1890963e2e979069f9f4d87f89f4959cpUsage:dockercp[OPTIONS]CONTAINER:PATHLOCALPATH|-dockercp[OPTIONS]LOCALPATH|-CONTAINER:PATHCopyfiles/foldersbetweenacontainerandthelocalfilesystemUse'-'asthesourcetoreadatararchivefromstdinandextractittoadirectorydestinationinacontainer.Use'-'asthedestinationtostreamatararchiveofacontainersourcetostdout.容器和宿主机之间相互copy文件1.将容器:/data/a.txt复制到本地当前目录#dockercp87cb69be18bb:/data/a.txt./2.将本地文件复制到容器:/data/backup目录下#dockercphelpdocker.tgz87cb69be18bb:/data/backup/3.将本地目录复制到容器:/data/backup目录下#dockercpdata87cb69be18bb:/data/backupcreateUsage:dockercreate[OPTIONS]IMAGE[COMMAND][ARG...]Createanewcontainer-a,--attach=[]AttachtoSTDIN,STDOUTorSTDERR--add-host=[]Addacustomhost-to-IPmapping(host:ip)--blkio-weight=0BlockIO(relativeweight),between10and1000--cpu-shares=0CPUshares(relativeweight)--cap-add=[]AddLinuxcapabilities--cap-drop=[]DropLinuxcapabilitiesdocker命令详解4/20--cgroup-parent=Optionalparentcgroupforthecontainer--cidfile=WritethecontainerIDtothefile--cpu-period=0LimitCPUCFS(CompletelyFairScheduler)period--cpu-quota=0LimitCPUCFS(CompletelyFairScheduler)quota--cpuset-cpus=CPUsinwhichtoallowexecution(0-3,0,1)--cpuset-mems=MEMsinwhichtoallowexecution(0-3,0,1)--device=[]Addahostdevicetothecontainer--disable-content-trust=trueSkipimageverification--dns=[]SetcustomDNSservers--dns-opt=[]SetDNSoptions--dns-search=[]SetcustomDNSsearchdomains-e,--env=[]Setenvironmentvariables--entrypoint=OverwritethedefaultENTRYPOINToftheimage--env-file=[]Readinafileofenvironmentvariables--expose=[]Exposeaportorarangeofports--group-add=[]Addadditionalgroupstojoin-h,--hostname=Containerhostname--help=falsePrintusage-i,--interactive=falseKeepSTDINopenevenifnotattached--ipc=IPCnamespacetouse--kernel-memory=Kernelmemorylimit-l,--label=[]Setmetadataonacontainer--label-file=[]Readinalinedelimitedfileoflabels--link=[]Addlinktoanothercontainer--log-driver=Loggingdriverforcontainer--log-opt=[]Logdriveroptions--lxc-conf=[]Addcustomlxcoptions-m,--memory=Memorylimit--mac-address=ContainerMACaddress(e.g.92:d0:c6:0a:29:33)--memory-reservation=Memorysoftlimit--memory-swap=Totalmemory(memory+swap),'-1'todisableswap--memory-swappiness=-1Tuningcontainermemoryswappiness(0to100)--name=Assignanametothecontainer--net=defaultSettheNetworkforthecontainer--oom-kill-disable=falseDisableOOMKiller-P,--publish-all=falsePublishallexposedportstorandomports-p,--publish=[]Publishacontainer'sport(s)tothehost--pid=PIDnamespacetouse--privileged=falseGiveextendedprivilegestothiscontainer--read-only=falseMountthecontainer'srootfilesystemasreadonly--restart=noRestartpolicytoapplywhenacontainerexits--security-opt=[]SecurityOp