Docker基础(2)——基础操作
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,1.Docker登入docker hub账号,(Docker hub上申请的账号即可)[root@www ~]# docker loginLogin with your Docker ID to pu
千家信息网最后更新 2026年11月01日Docker基础(2)——基础操作
1.Docker登入docker hub账号,(Docker hub上申请的账号即可)
[root@www ~]# docker loginLogin with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.Username: ******Password:WARNING! Your password will be stored unencrypted in /root/.docker/config.json.Configure a credential helper to remove this warning. Seehttps://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded
2.搜索镜像库中的镜像;
[root@www ~]# docker search nginxNAME DESCRIPTION STARS OFFICIAL AUTOMATEDnginx Official build of Nginx. 10250 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1462 [OK]richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 647 [OK]jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as p… 438 [OK]kong Open-source Microservice & API Management la… 247 [OK] webdevops/php-nginx Nginx with PHP-FPM 117 [OK]kitematic/hello-world-nginx A light-weight nginx container that demonstr… 112 zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 75 [OK]bitnami/nginx Bitnami nginx Docker Image 58 [OK]1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 47 [OK]linuxserver/nginx An Nginx container, brought to you by LinuxS… 43 tobi312/rpi-nginx NGINX on Raspberry Pi / armhf 23 [OK]blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 12 [OK]nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 12 wodby/drupal-nginx Nginx for Drupal container image 11 [OK]centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 8 nginxdemos/hello NGINX webserver that serves a simple page co… 8 [OK]centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 5 1science/nginx Nginx Docker images that include Consul Temp… 4 [OK]travix/nginx NGinx reverse proxy 2 [OK]pebbletech/nginx-proxy nginx-proxy sets up a container running ngin… 2 [OK]mailu/nginx Mailu nginx frontend 2 [OK]toccoag/openshift-nginx Nginx reverse proxy for Nice running on same… 1 [OK]wodby/nginx Generic nginx 0 [OK]ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 0 [OK]
3.docker拉取存在docker hub上的镜像至本地(下载Docker hub上的镜像);
[root@www ~]# docker pull httpd:2.4.37-alpine2.4.37-alpine: Pulling from library/httpd4fe2ade4980c: Already exists42101a4e4c4e: Pull complete73eadb9961ff: Pull complete830983fb5ec2: Pull complete78fb51bbfc27: Pull completeDigest: sha256:b875793145fe613aa2d1f73f1cd8ec09b775abcd6980024bc60a6a9c73d644fcStatus: Downloaded newer image for httpd:2.4.37-alpine[root@www ~]# docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEhttpd 2.4.37-alpine 11fc0c2a2dfa 4 days ago 91.8MBnginx 1.14-alpine 77bae8d00654 13 days ago 17.7MBljymyy/nginx latest 77bae8d00654 13 days ago 17.7MB
4.基于容器制作镜像
[root@www ~]# docker container run --name httpd1 httpd:2.4.37-alpineAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this messageAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message[Tue Nov 20 09:19:04.710155 2018] [mpm_event:notice] [pid 1:tid 140394175941512] AH00489: Apache/2.4.37 (Unix) configured -- resuming normal operations[Tue Nov 20 09:19:04.719195 2018] [core:notice] [pid 1:tid 140394175941512] AH00094: Command line: 'httpd -D FOREGROUND'
[root@www ~]# docker exec -it httpd1 /bin/sh/usr/local/apache2 #/usr/local/apache2 # vi htdocs/index.html/usr/local/apache2 # exit[root@www ~]# docker commit httpd1 ljymyy/httpd:privatesha256:0c28c4522c128a7dca17c26d2fd8eee4e57642b455c067832d5567da1128da5e[root@www ~]# docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEljymyy/httpd private 0c28c4522c12 6 seconds ago 91.8MBhttpd 2.4.37-alpine 11fc0c2a2dfa 4 days ago 91.8MBnginx 1.14-alpine 77bae8d00654 13 days ago 17.7MBljymyy/nginx latest 77bae8d00654 13 days ago 17.7MB [root@www ~]# curl 172.17.0.2It works!
test successful
测试:
[root@www ~]# docker run --name httpd2 --rm ljymyy/httpd:privateAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this messageAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message[Tue Nov 20 09:39:27.805890 2018] [mpm_event:notice] [pid 1:tid 140674896550792] AH00489: Apache/2.4.37 (Unix) configured -- resuming normal operations[Tue Nov 20 09:39:27.806444 2018] [core:notice] [pid 1:tid 140674896550792] AH00094: Command line: 'httpd -D FOREGROUND'172.17.0.1 - - [20/Nov/2018:09:39:39 +0000] "GET / HTTP/1.1" 200 63 [root@www ~]# curl 172.17.0.3It works!
test successful
5.为镜像打标签;(IMAGE ID为相同的)
[root@www ~]# docker tag ljymyy/httpd:private ljymyy/httpd:v2.0[root@www ~]# docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEljymyy/httpd private 0c28c4522c12 5 minutes ago 91.8MBljymyy/httpd v2.0 0c28c4522c12 5 minutes ago 91.8MBhttpd 2.4.37-alpine 11fc0c2a2dfa 4 days ago 91.8MBljymyy/nginx latest 77bae8d00654 13 days ago 17.7MBnginx 1.14-alpine 77bae8d00654 13 days ago 17.7MB
6.将本地镜像上传至docker hub库中;
在docker hub上的dashboard中创建一个个人的Repository;创建相对应的namespace和repository name;例如:ljymyy/httpd

[root@www ~]# docker push ljymyy/httpd:v2.0The push refers to repository [docker.io/ljymyy/httpd]9dd07a03f263: Layer already exists86503dd49098: Layer already exists9caa02067460: Layer already exists05f824de9453: Layer already exists7df053e22514: Layer already existsdf64d3292fd6: Layer already existsv2.0: digest: sha256:5b3aea8b8ed49fc642f46282c8bfeabf023fcbde0635341401a37ba0778af2a3 size: 1569
7.将镜像导入至文件中和导出文件中的镜像至本地;
[root@www ~]# docker save -o test.file nginx:1.14-alpine[root@www ~]# docker load -q -i test.fileLoaded image: nginx:1.14-alpine
8.显示容器的详细信息;
[root@www ~]# docker container lsCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES6246bc53550b httpd:2.4.37-alpine "httpd-foreground" 3 hours ago Up 18 seconds 80/tcp httpd1[root@www ~]# docker inspect httpd1[ { "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 } } } }]
镜像
容器
文件
账号
基础
相同
个人
信息
标签
中创
制作
搜索
测试
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
南京欣网互联网络科技
广东万易互联网科技有限公司惠州分公司
科技互联网技术
上海互联网科技有限公司
互联网科技公司官网
互联网科技博客
左右互联网络科技
深圳卡尔迅互联网科技有限公司怎么样
深圳互联网科技怎么样
互联网校园科技培训
河南猎农互联网科技有限公司
乌苏新华互联网科技做什么的
长沙茂晟互联网科技有限公司
互联网科技实习生岗位
领航科技大厦互联网公司
广州燕处互联网科技有限公司
张家口科技产业互联网平台
福仕德教育科技互联网
众联互联网络科技
陕西彩京云互联网科技有限公司
西安纸贵互联网科技有限公司
深圳期待互联网科技
太原新华互联网科技学校怎么样
博兴的互联网电子科技公司
互联网软件和科技
苏州五指互联网络科技有限
互联网金融科技展
重庆科技产业互联网有哪些
互联网科技创新方面的资料
颐高云石互联网科技
- 上一篇
如何分析Kubernetes的卷克隆Alpha
如何分析Kubernetes的卷克隆Alpha,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。什么是克隆?许多存储系统提供创建卷的"克
- 下一篇
vmware centos7 clone mac地址导致Failed to start LSB: Bring up/down networking错误怎么办
这篇文章将为大家详细讲解有关 vmware centos7 clone mac地址导致Failed to start LSB: Bring up/down networking错误怎么办,小编觉得挺实