Docker基础(2)——基础操作

云计算

1.Docker登入docker hub账号,(Docker hub上申请的账号即可)

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站制作、成都网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的中山网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
[root@www~]#dockerlogin
LoginwithyourDockerIDtopushandpullimagesfromDockerHub.Ifyoudon'thaveaDockerID,headovertohttps://hub.docker.comtocreateone.
Username:******
Password:
WARNING!Yourpasswordwillbestoredunencryptedin/root/.docker/config.json.
Configureacredentialhelpertoremovethiswarning.See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

LoginSucceeded

2.搜索镜像库中的镜像;

[root@www~]#dockersearchnginx
NAMEDESCRIPTIONSTARSOFFICIALAUTOMATED
nginxOfficialbuildofNginx.10250[OK]
jwilder/nginx-proxyAutomatedNginxreverseproxyfordockercon…1462[OK]
richarvey/nginx-php-fpmContainerrunningNginx+PHP-FPMcapableof…647[OK]
jrcs/letsencrypt-nginx-proxy-companionLetsEncryptcontainertousewithnginxasp…438[OK]
kongOpen-sourceMicroservice&APIManagementla…247[OK]
webdevops/php-nginxNginxwithPHP-FPM117[OK]
kitematic/hello-world-nginxAlight-weightnginxcontainerthatdemonstr…112
zabbix/zabbix-web-nginx-mysqlZabbixfrontendbasedonNginxweb-serverwi…75[OK]
bitnami/nginxBitnaminginxDockerImage58[OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-Mysql-5ubuntu-16-nginx-php-phpmyadmin-MYSQL-547[OK]
linuxserver/nginxAnNginxcontainer,broughttoyoubyLinuxS…43
tobi312/rpi-nginxNGINXonRaspberryPi/armhf23[OK]
blacklabelops/nginxDockerizedNginxReverseProxyServer.12[OK]
nginx/nginx-ingressNGINXIngressControllerforKubernetes12
wodby/drupal-nginxNginxforDrupalcontainerimage11[OK]
centos/nginx-18-centos7Platformforrunningnginx1.8orbuildingn…8
nginxdemos/helloNGINXwebserverthatservesasimplepageco…8[OK]
centos/nginx-112-centos7Platformforrunningnginx1.12orbuilding…5
1science/nginxNginxDockerimagesthatincludeConsulTemp…4[OK]
travix/nginxNGinxreverseproxy2[OK]
pebbletech/nginx-proxynginx-proxysetsupacontainerrunningngin…2[OK]
mailu/nginxMailunginxfrontend2[OK]
toccoag/openshift-nginxNginxreverseproxyforNicerunningonsame…1[OK]
wodby/nginxGenericnginx0[OK]
ansibleplaybookbundle/nginx-apbAnAPBtodeployNGINX0[OK]

3.docker拉取存在docker hub上的镜像至本地(下载Docker hub上的镜像);

[root@www~]#dockerpullhttpd:2.4.37-alpine
2.4.37-alpine:Pullingfromlibrary/httpd
4fe2ade4980c:Alreadyexists
42101a4e4c4e:Pullcomplete
73eadb9961ff:Pullcomplete
830983fb5ec2:Pullcomplete
78fb51bbfc27:Pullcomplete
Digest:sha256:b875793145fe613aa2d1f73f1cd8ec09b775abcd6980024bc60a6a9c73d644fc
Status:Downloadednewerimageforhttpd:2.4.37-alpine
[root@www~]#dockerimagels
REPOSITORYTAGIMAGEIDCREATEDSIZE
httpd2.4.37-alpine11fc0c2a2dfa4daysago91.8MB
nginx1.14-alpine77bae8d0065413daysago17.7MB
ljymyy/nginxlatest77bae8d0065413daysago17.7MB

4.基于容器制作镜像

[root@www~]#dockercontainerrun--namehttpd1httpd:2.4.37-alpine
AH00558:httpd:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,using172.17.0.2.Setthe'ServerName'directivegloballytosuppressthismessage
AH00558:httpd:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,using172.17.0.2.Setthe'ServerName'directivegloballytosuppressthismessage
[TueNov2009:19:04.7101552018][mpm_event:notice][pid1:tid140394175941512]AH00489:Apache/2.4.37(Unix)configured--resumingnormaloperations
[TueNov2009:19:04.7191952018][core:notice][pid1:tid140394175941512]AH00094:Commandline:'httpd-DFOREGROUND'
[root@www~]#dockerexec-ithttpd1/bin/sh
/usr/local/apache2#
/usr/local/apache2#vihtdocs/index.html
/usr/local/apache2#exit
[root@www~]#dockercommithttpd1ljymyy/httpd:private
sha256:0c28c4522c128a7dca17c26d2fd8eee4e57642b455c067832d5567da1128da5e
[root@www~]#dockerimagels
REPOSITORYTAGIMAGEIDCREATEDSIZE
ljymyy/httpdprivate0c28c4522c126secondsago91.8MB
httpd2.4.37-alpine11fc0c2a2dfa4daysago91.8MB
nginx1.14-alpine77bae8d0065413daysago17.7MB
ljymyy/nginxlatest77bae8d0065413daysago17.7MB


[root@www~]#curl172.17.0.2

Itworks!

testsuccessful

测试:

[root@www~]#dockerrun--namehttpd2--rmljymyy/httpd:private
AH00558:httpd:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,using172.17.0.3.Setthe'ServerName'directivegloballytosuppressthismessage
AH00558:httpd:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,using172.17.0.3.Setthe'ServerName'directivegloballytosuppressthismessage
[TueNov2009:39:27.8058902018][mpm_event:notice][pid1:tid140674896550792]AH00489:Apache/2.4.37(Unix)configured--resumingnormaloperations
[TueNov2009:39:27.8064442018][core:notice][pid1:tid140674896550792]AH00094:Commandline:'httpd-DFOREGROUND'
172.17.0.1--[20/Nov/2018:09:39:39+0000]"GET/HTTP/1.1"20063


[root@www~]#curl172.17.0.3

Itworks!

testsuccessful

5.为镜像打标签;(IMAGE ID为相同的)

[root@www~]#dockertagljymyy/httpd:privateljymyy/httpd:v2.0
[root@www~]#dockerimagels
REPOSITORYTAGIMAGEIDCREATEDSIZE
ljymyy/httpdprivate0c28c4522c125minutesago91.8MB
ljymyy/httpdv2.00c28c4522c125minutesago91.8MB
httpd2.4.37-alpine11fc0c2a2dfa4daysago91.8MB
ljymyy/nginxlatest77bae8d0065413daysago17.7MB
nginx1.14-alpine77bae8d0065413daysago17.7MB

6.将本地镜像上传至docker hub库中;

在docker hub上的dashboard中创建一个个人的Repository;创建相对应的namespace和repository name;例如:ljymyy/httpd

[root@www~]#dockerpushljymyy/httpd:v2.0
Thepushreferstorepository[docker.io/ljymyy/httpd]
9dd07a03f263:Layeralreadyexists
86503dd49098:Layeralreadyexists
9caa02067460:Layeralreadyexists
05f824de9453:Layeralreadyexists
7df053e22514:Layeralreadyexists
df64d3292fd6:Layeralreadyexists
v2.0:digest:sha256:5b3aea8b8ed49fc642f46282c8bfeabf023fcbde0635341401a37ba0778af2a3size:1569

7.将镜像导入至文件中和导出文件中的镜像至本地;

[root@www~]#dockersave-otest.filenginx:1.14-alpine
[root@www~]#dockerload-q-itest.file
Loadedimage:nginx:1.14-alpine

8.显示容器的详细信息;

[root@www~]#dockercontainerls
CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES
6246bc53550bhttpd:2.4.37-alpine"httpd-foreground"3hoursagoUp18seconds80/tcphttpd1
[root@www~]#dockerinspecthttpd1
[
{
"Id":"6246bc53550bcfa1149f9f51b48a5b992969d3e2eb50df457cb0f06589102a01",
"Created":"2018-11-20T09:18:58.780749029Z",
"Path":"httpd-foreground",
"Args":[],
"State":{
"Status":"running",
"Running":true,
"Paused":false,
"Restarting":false,
"OOMKilled":false,
"Dead":false,
"Pid":67850,
"ExitCode":0,
"Error":"",
"StartedAt":"2018-11-20T11:50:26.409306755Z",
"FinishedAt":"2018-11-20T09:40:54.02714799Z"
},
"Image":"sha256:11fc0c2a2dfa90eb5804742e5b0927c9cacc3664ffde7839dcc6f39e6fd44fcb",
"ResolvConfPath":"/var/lib/docker/containers/6246bc53550bcfa1149f9f51b48a5b992969d3e2eb50df457cb0f06589102a01/resolv.conf",
"HostnamePath":"/var/lib/docker/containers/6246bc53550bcfa1149f9f51b48a5b992969d3e2eb50df457cb0f06589102a01/hostname",
"HostsPath":"/var/lib/docker/containers/6246bc53550bcfa1149f9f51b48a5b992969d3e2eb50df457cb0f06589102a01/hosts",
"LogPath":"/var/lib/docker/containers/6246bc53550bcfa1149f9f51b48a5b992969d3e2eb50df457cb0f06589102a01/6246bc53550bcfa1149f9f51b48a5b992969d3e2eb50df457cb0f06589102a01-json.log",
"Name":"/httpd1",
"RestartCount":0,
"Driver":"overlay2",
"Platform":"linux",
"MountLabel":"",
"ProcessLabel":"",
"AppArmorProfile":"",
"ExecIDs":null,
"HostConfig":{
"Binds":null,
"ContainerIDFile":"",
"LogConfig":{
"Type":"json-file",
"Config":{}
},
"NetworkMode":"default",
"PortBindings":{},
"RestartPolicy":{
"Name":"no",
"MaximumRetryCount":0
},
"AutoRemove":false,
"VolumeDriver":"",
"VolumesFrom":null,
"CapAdd":null,
"CapDrop":null,
"dns":[],
"DnsOptions":[],
"DnsSearch":[],
"ExtraHosts":null,
"GroupAdd":null,
"IpcMode":"shareable",
"Cgroup":"",
"Links":null,
"OomScoreAdj":0,
"PidMode":"",
"Privileged":false,
"PublishAllPorts":false,
"ReadonlyRootfs":false,
"SecurityOpt":null,
"UTSMode":"",
"UsernsMode":"",
"ShmSize":67108864,
"Runtime":"runc",
"ConsoleSize":[
0,
0
],
"Isolation":"",
"CpuShares":0,
"Memory":0,
"NanoCpus":0,
"CgroupParent":"",
"BlkioWeight":0,
"BlkioWeightDevice":[],
"BlkioDeviceReadBps":null,
"BlkioDeviceWriteBps":null,
"BlkioDeviceReadIOps":null,
"BlkioDeviceWriteIOps":null,
"CpuPeriod":0,
"CpuQuota":0,
"CpuRealtimePeriod":0,
"CpuRealtimeRuntime":0,
"CpusetCpus":"",
"CpusetMems":"",
"Devices":[],
"DeviceCgroupRules":null,
"DiskQuota":0,
"KernelMemory":0,
"MemoryReservation":0,
"MemorySwap":0,
"MemorySwappiness":null,
"OomKillDisable":false,
"PidsLimit":0,
"Ulimits":null,
"CpuCount":0,
"CpuPercent":0,
"IOMaximumIOps":0,
"IOMaximumBandwidth":0,
"MaskedPaths":[
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths":[
"/proc/asound",
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver":{
"Data":{
"LowerDir":"/var/lib/docker/overlay2/02719a1efc3bd4ced5a4692b75468dd4d2d55fa254869cbc26d9487ebea1c5ea-init/diff:/var/lib/docker/overlay2/0403b4e021b6fb5d30d752fa1f8d0dbe7e5b5fae974ddcc3acc8c32fe49e51f8/diff:/var/lib/docker/overlay2/7e600ef93457c34d8423b1fa59037800b630f992ca26b0289106f4bb4edbbda8/diff:/var/lib/docker/overlay2/56de63abd81931dc78929016b95e51e3d74f4702d90af28590b31ad44bd9335e/diff:/var/lib/docker/overlay2/9efe9a470ec8834a8605274fa2b156015bc703c790b429ac13fdd10f19693ccd/diff:/var/lib/docker/overlay2/2cd347e2a7d82ceeb12f18b279dda0fa0853f13ab3149aa0787f3f7c685ba622/diff",
"MergedDir":"/var/lib/docker/overlay2/02719a1efc3bd4ced5a4692b75468dd4d2d55fa254869cbc26d9487ebea1c5ea/merged",
"UpperDir":"/var/lib/docker/overlay2/02719a1efc3bd4ced5a4692b75468dd4d2d55fa254869cbc26d9487ebea1c5ea/diff",
"WorkDir":"/var/lib/docker/overlay2/02719a1efc3bd4ced5a4692b75468dd4d2d55fa254869cbc26d9487ebea1c5ea/work"
},
"Name":"overlay2"
},
"Mounts":[],
"Config":{
"Hostname":"6246bc53550b",
"Domainname":"",
"User":"",
"AttachStdin":true,
"AttachStdout":true,
"AttachStderr":true,
"ExposedPorts":{
"80/tcp":{}
},
"Tty":true,
"OpenStdin":true,
"StdinOnce":true,
"Env":[
"PATH=/usr/local/apache2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"HTTPD_PREFIX=/usr/local/apache2",
"HTTPD_VERSION=2.4.37",
"HTTPD_SHA256=3498dc5c6772fac2eb7307dc7963122ffe243b5e806e0be4fb51974ff759d726",
"HTTPD_PATCHES=",
"APACHE_DIST_URLS=https://www.apache.org/dyn/closer.cgi?action=download&filename=\\thttps://www-us.apache.org/dist/\\thttps://www.apache.org/dist/\\thttps://archive.apache.org/dist/"
],
"Cmd":[
"httpd-foreground"
],
"ArgsEscaped":true,
"Image":"httpd:2.4.37-alpine",
"Volumes":null,
"WorkingDir":"/usr/local/apache2",
"Entrypoint":null,
"OnBuild":null,
"Labels":{}
},
"NetworkSettings":{
"Bridge":"",
"SandboxID":"948daf1d078778001fa043b74a10733c11e215be3a8b457b16a47d8b46f087aa",
"HairpinMode":false,
"LinkLocalIPv6Address":"",
"LinkLocalIPv6PrefixLen":0,
"Ports":{
"80/tcp":null
},
"SandboxKey":"/var/run/docker/netns/948daf1d0787",
"SecondaryIPAddresses":null,
"SecondaryIPv6Addresses":null,
"EndpointID":"a591d3f3fbf35606173c7f121a3e23503d075473d256cae6c55933cf91815172",
"Gateway":"172.17.0.1",
"GlobalIPv6Address":"",
"GlobalIPv6PrefixLen":0,
"IPAddress":"172.17.0.2",
"IPPrefixLen":16,
"IPv6Gateway":"",
"MacAddress":"02:42:ac:11:00:02",
"Networks":{
"bridge":{
"IPAMConfig":null,
"Links":null,
"Aliases":null,
"NetworkID":"6714eb554a2843bd0582a3e7d63b09b175c5351c100aab08b1a051bc8187cb5c",
"EndpointID":"a591d3f3fbf35606173c7f121a3e23503d075473d256cae6c55933cf91815172",
"Gateway":"172.17.0.1",
"IPAddress":"172.17.0.2",
"IPPrefixLen":16,
"IPv6Gateway":"",
"GlobalIPv6Address":"",
"GlobalIPv6PrefixLen":0,
"MacAddress":"02:42:ac:11:00:02",
"DriverOpts":null
}
}
}
}
]


文章名称:Docker基础(2)——基础操作
文章URL:http://cdiso.cn/article/cgjiij.html

其他资讯