####安裝dockerjava
# yum install docker-io -ylinux
# service docker start && chkconfig docker onweb
####使用dockerdocker
#####查看docker版本平臺等信息apache
# docker infojson
Containers: 0 Images: 0 Storage Driver: devicemapper Pool Name: docker-253:0-407342-pool Pool Blocksize: 65.54 kB Backing Filesystem: extfs Data file: /dev/loop0 Metadata file: /dev/loop1 Data Space Used: 305.7 MB Data Space Total: 107.4 GB Data Space Available: 1.11 GB Metadata Space Used: 729.1 kB Metadata Space Total: 2.147 GB Metadata Space Available: 1.11 GB Udev Sync Supported: true Deferred Removal Enabled: false Data loop file: /var/lib/docker/devicemapper/devicemapper/data Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata Library Version: 1.02.89-RHEL6 (2014-09-01) Execution Driver: native-0.2 Logging Driver: json-file Kernel Version: 2.6.32-504.el6.x86_64 Operating System: <unknown> CPUs: 1 Total Memory: 1.833 GiB Name: ops1 ID: MSN6:C6TZ:4LDD:VMGC:PTRP:6WQD:WHN2:674S:E2AQ:DPT6:T4B2:S6U4
# docker versionbootstrap
Client version: 1.7.1 Client API version: 1.19 Go version (client): go1.4.2 Git commit (client): 786b29d/1.7.1 OS/Arch (client): linux/amd64 Server version: 1.7.1 Server API version: 1.19 Go version (server): go1.4.2 Git commit (server): 786b29d/1.7.1 OS/Arch (server): linux/amd64
#####查找鏡像tomcat
# docker search tomcatbash
NAME DESCRIPTION STARS OFFICIAL AUTOMATED tomcat Apache Tomcat is an open source implementa... 615 [OK] dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 ba... 16 [OK] consol/tomcat-7.0 Tomcat 7.0.57, 8080, "admin/admin" 14 [OK] ......
#####下載鏡像app
# docker pull tomcat
latest: Pulling from tomcat 6b8a1ecb2364: Downloading [======> ] 6.815 MB/51.34 MB d1cc0e6af849: Download complete ....... Digest: sha256:d2eeba2fc1da6d9a092bd103b69b527196155568b723eb67e0355033f3a3af29 Status: Downloaded newer image for tomcat:lates
#####查看鏡像
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE tomcat latest 430e8c6b6fad 2 weeks ago 357.3 MB
# docker run tomcat ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 10712 1040 ? Rs 10:20 0:00 ps aux
# docker run -i -t tomcat /bin/bash #交互式運行docker
root@2c463985a339:/usr/local/tomcat# /usr/local/tomcat/bin/startup.sh Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/lib/jvm/java-7-openjdk-amd64/jre Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started.
#####查看容器
# docker ps -a #-a顯示全部容器,-l 顯示最近的容器,不加參數顯示運行的
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2c463985a339 tomcat "/bin/bash" 4 minutes ago Exited (130) 3 minutes ago boring_yonath 91f5e029a64d tomcat "/bin/bash" 5 minutes ago Exited (0) 4 minutes ago kickass_babbage 5f67b78ba369 tomcat "/bin/bash" 11 minutes ago Exited (6) 5 minutes ago clever_jones b11510e7338f tomcat "ps aux" 15 minutes ago Exited (0) 15 minutes ago jolly_perlman 576870dde984 tomcat "ps aux" 15 minutes ago fervent_goodall 3aefc748e778 tomcat "ps aux|grep java" 15 minutes ago clever_goodall fa98a00818ad tomcat "ls /etc/init.d/" 16 minutes ago Exited (0) 16 minutes ago serene_ptolemy 944adce8d00a tomcat "ls /" 16 minutes ago Exited (0) 16 minutes ago naughty_mayer
#####啓動一個容器
# docker start 2c463985a339 #除了start還支持stop,restart,kill
2c463985a339
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2c463985a339 tomcat "/bin/bash" 14 minutes ago Up 59 seconds 8080/tcp boring_yonath
#####對運行中的容器進行操做
建議使用exec方式,
# docker attach 2c463985a339
root@2c463985a339:/usr/local/tomcat# ls LICENSE NOTICE RELEASE-NOTES RUNNING.txt bin conf lib logs temp webapps work root@2c463985a339:/usr/local/tomcat# ps aux|grep java root 7 0.0 0.0 12756 1008 ? S+ 10:47 0:00 grep java root@2c463985a339:/usr/local/tomcat# /usr/local/tomcat/bin/startup.sh Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/lib/jvm/java-7-openjdk-amd64/jre Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started. root@2c463985a339:/usr/local/tomcat# ps aux|grep java root 15 72.5 4.1 1555972 80468 ? Sl 10:47 0:04 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start root 37 0.0 0.0 11072 684 ? R+ 10:47 0:00 grep java
# docker exec -it bbc55c1a511a /bin/bash
root@bbc55c1a511a:/usr/local/tomcat# ls LICENSE NOTICE RELEASE-NOTES RUNNING.txt bin conf lib logs temp webapps work root@bbc55c1a511a:/usr/local/tomcat# ps aux|grep tomcat root 1 0.0 3.8 1555972 74784 ? Ssl Apr21 0:48 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start root 37 0.0 0.0 12756 1008 ? S+ 11:38 0:00 grep tomcat
#####查看容器的鏡像的詳細信息
# docker inspect 2c463985a339
[ { "Id": "2c463985a339974f1d1e1059b8d69c4c097ff77938ff4be9f4a7311a7b364bbc", "Created": "2016-04-21T10:30:57.705132242Z", "Path": "/bin/bash", "Args": [], "State": { "Running": false, "Paused": false, "Restarting": false, "OOMKilled": true, "Dead": false, "Pid": 0, "ExitCode": 1, "Error": "", "StartedAt": "2016-04-21T10:48:56.306897656Z", "FinishedAt": "2016-04-21T10:53:04.174892969Z" }, "Image": "430e8c6b6fad608dfc9cdb28006896b39104ba98589832c4be7ae12234a6161a", "NetworkSettings": { "Bridge": "", "EndpointID": "", "Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "HairpinMode": false, "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "MacAddress": "", "NetworkID": "", "PortMapping": null, "Ports": null, "SandboxKey": "", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null }, "ResolvConfPath": "/var/lib/docker/containers/2c463985a339974f1d1e1059b8d69c4c097ff77938ff4be9f4a7311a7b364bbc/resolv.conf", "HostnamePath": "/var/lib/docker/containers/2c463985a339974f1d1e1059b8d69c4c097ff77938ff4be9f4a7311a7b364bbc/hostname", "HostsPath": "/var/lib/docker/containers/2c463985a339974f1d1e1059b8d69c4c097ff77938ff4be9f4a7311a7b364bbc/hosts", "LogPath": "/var/lib/docker/containers/2c463985a339974f1d1e1059b8d69c4c097ff77938ff4be9f4a7311a7b364bbc/2c463985a339974f1d1e1059b8d69c4c097ff77938ff4be9f4a7311a7b364bbc-json.log", "Name": "/boring_yonath", "RestartCount": 0, "Driver": "devicemapper", "ExecDriver": "native-0.2", "MountLabel": "", "ProcessLabel": "", "Volumes": {}, "VolumesRW": {}, "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LxcConf": [], "Memory": 0, "MemorySwap": 0, "CpuShares": 0, "CpuPeriod": 0, "CpusetCpus": "", "CpusetMems": "", "CpuQuota": 0, "BlkioWeight": 0, "OomKillDisable": false, "Privileged": false, "PortBindings": {}, "Links": null, "PublishAllPorts": false, "Dns": null, "DnsSearch": null, "ExtraHosts": null, "VolumesFrom": null, "Devices": [], "NetworkMode": "bridge", "IpcMode": "", "PidMode": "", "UTSMode": "", "CapAdd": null, "CapDrop": null, "RestartPolicy": { "Name": "no", "MaximumRetryCount": 0 }, "SecurityOpt": null, "ReadonlyRootfs": false, "Ulimits": null, "LogConfig": { "Type": "json-file", "Config": {} }, "CgroupParent": "" }, "Config": { "Hostname": "2c463985a339", "Domainname": "", "User": "", "AttachStdin": true, "AttachStdout": true, "AttachStderr": true, "PortSpecs": null, "ExposedPorts": { "8080/tcp": {} }, "Tty": true, "OpenStdin": true, "StdinOnce": true, "Env": [ "PATH=/usr/local/tomcat/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "LANG=C.UTF-8", "JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre", "JAVA_VERSION=7u95", "JAVA_DEBIAN_VERSION=7u95-2.6.4-1~deb8u1", "CATALINA_HOME=/usr/local/tomcat", "TOMCAT_MAJOR=8", "TOMCAT_VERSION=8.0.33", "TOMCAT_TGZ_URL=https://www.apache.org/dist/tomcat/tomcat-8/v8.0.33/bin/apache-tomcat-8.0.33.tar.gz" ], "Cmd": [ "/bin/bash" ], "Image": "tomcat", "Volumes": null, "VolumeDriver": "", "WorkingDir": "/usr/local/tomcat", "Entrypoint": null, "NetworkDisabled": false, "MacAddress": "", "OnBuild": null, "Labels": {} } } ]
#####從容器中製做鏡像
# docker commit 2c463985a339 mytomcat:1
f226b712d77b54ae9ec3107e41c21f14c506937e63fb136a79d0cbd62e469ee9
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE mytomcat 1 f226b712d77b About a minute ago 357.4 MB tomcat latest 430e8c6b6fad 2 weeks ago 357.3 MB
#####刪除容器和鏡像
# docker rm 2c463985a339
2c463985a339
# docker rmi mytomcat:1
Untagged: mytomcat:1 Deleted: f226b712d77b54ae9ec3107e41c21f14c506937e63fb136a79d0cbd62e469ee9