docker pull image:version
如果不带version,那么为最新版的lastest。如果带version,在docker hub里找不到的话会报错。
docker push
如果不带version,那么为最新版的lastest。如果带version,在docker hub里找不到的话会报错。
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker stop
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker rm
docker images|grep none|awk '{print $3 }'|xargs docker rmi
原理:
先停止引用了None镜像的容器,然后再移除掉该容器,最后移除掉无用None镜像。
docker rmi IMAGE ID/REPOSITORY
如果指定的IMAGE ID 或者 REPOSITORY不存在的话,那么就会报错提示。
docker ps
docker ps -a
查看所有的容器,包含没有在运行的容器。
docker run
例如运行mysql:
docker run -itd --name my-mysql -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password mysql:5.7
docker run --name my-nginx -p 80:80 \
-v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /data/nginx/log:/var/log/nginx \
-v /data/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf \
-d nginx
注: 指定的端口不能重复,否则会出现占用的问题。
docker stop NAMES/CONTAINER ID
docker start NAMES/CONTAINER ID
docker rm NAMES/CONTAINER ID
NAMES/CONTAINER ID 为容器的名称和容器ID
docker container prune
docker run -it ubuntu bash
进入到ubuntu 容器里的终端,可以与ubuntu容器进行交互。
docker exec -it CONTAINERID/NAMES bash
进入到指定 CONTAINERID/NAMES 的容器里,使用exit指令退出终端, 推荐使用此方式进入到容器里。
docker stats
此命令可以查看docker 应用中占用资源的信息,包含CPU、内存、占用带宽等。
docker login
此命令用于登录到docker hub, 从Docker hub拉取镜像的时候需要作验证。
docker logs CONTAINERID/NAMES
docker top CONTAINERID/NAMES
docker inspect CONTAINERID/NAMES
返回的是一个json数据结构,从结构中可以获取到容器的一些相关信息。
root@iZbp15tyvtnvvqvgouyvisZ:~/python/myapp/mysite# docker inspect mysite-v5
[
{
"Id": "913fcccaa6b550ca0fd1164a33478874e1be12e60f0e24499b8a14aaeadf3512",
"Created": "2021-02-05T08:13:02.469630747Z",
"Path": "python",
"Args": [
"./manage.py",
"runserver",
"0.0.0.0:8003"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 4418,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-02-05T08:13:02.912255422Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:44c3a6078c4a3c6df80056a8beaced2836d856c85e910c0445659eb3bbbcd485",
"ResolvConfPath": "/var/lib/docker/containers/913fcccaa6b550ca0fd1164a33478874e1be12e60f0e24499b8a14aaeadf3512/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/913fcccaa6b550ca0fd1164a33478874e1be12e60f0e24499b8a14aaeadf3512/hostname",
"HostsPath": "/var/lib/docker/containers/913fcccaa6b550ca0fd1164a33478874e1be12e60f0e24499b8a14aaeadf3512/hosts",
"LogPath": "/var/lib/docker/containers/913fcccaa6b550ca0fd1164a33478874e1be12e60f0e24499b8a14aaeadf3512/913fcccaa6b550ca0fd1164a33478874e1be12e60f0e24499b8a14aaeadf3512-json.log",
"Name": "/mysite-v5",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {
}
},
"NetworkMode": "default",
"PortBindings": {
"8003/tcp": [
{
"HostIp": "",
"HostPort": "8003"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "host",
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"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,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/ca88c458b60846c12b248ecef66a5f13f5b08fdf3d4b5fc09461a05173df0ae6-init/diff:/var/lib/docker/overlay2/995eb3951ec5cb846e660f9354c4513e67f4af6400bfeabca3f09df4372b7b37/diff:/var/lib/docker/overlay2/d47590117a40b38c1616a2f13000878dfc91549d5afdcb005df0c2a354a06f23/diff:/var/lib/docker/overlay2/6e4096143bbcedf1ab2872770c8ec6cd4517e1547323d359827c7facb3d618af/diff:/var/lib/docker/overlay2/a4ad084edaf7a6f2c71f3af60aca90a2c68f6d1d63cf444c9b15e984b3ecda7c/diff:/var/lib/docker/overlay2/dd4ba1f371b56514c26c64d2a52aa076ccb2604f059d3f84f4a088c514e27403/diff:/var/lib/docker/overlay2/f4c0d0dc9234fd561750edf1a54536ed5602606fe5f95712bc7aea3e48075409/diff:/var/lib/docker/overlay2/7953e1a911e565696060fcb4471107df253fe81482fa76ae7c561c1ad71b60a7/diff:/var/lib/docker/overlay2/f8d41901cc2eaf6d337812b8900eacaabe2c5f66d2a2085a2dce6fb6eb6e9625/diff:/var/lib/docker/overlay2/7b65c1e78213eb80673137dc9259c18c2b421ac6017874dbecf852f040fd8664/diff:/var/lib/docker/overlay2/891220bf9835b739b07ef6197389b47ac53f2ef08a8107a9875a4602ed9b04d5/diff:/var/lib/docker/overlay2/96c631c50078fa61c3dd2976e4fc95beb848f61460c3c2270a07b972960c299d/diff",
"MergedDir": "/var/lib/docker/overlay2/ca88c458b60846c12b248ecef66a5f13f5b08fdf3d4b5fc09461a05173df0ae6/merged",
"UpperDir": "/var/lib/docker/overlay2/ca88c458b60846c12b248ecef66a5f13f5b08fdf3d4b5fc09461a05173df0ae6/diff",
"WorkDir": "/var/lib/docker/overlay2/ca88c458b60846c12b248ecef66a5f13f5b08fdf3d4b5fc09461a05173df0ae6/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "913fcccaa6b5",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"8003/tcp": {
}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/bin: /usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"GPG_KEY=0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D",
"PYTHON_VERSION=3.7.9",
"PYTHON_PIP_VERSION=21.0.1",
"PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/4be3fe44ad9dedc028629ed1497052d65d281b8e/get-pip.py",
"PYTHON_GET_PIP_SHA256=8006625804f55e1bd99ad4214fd07082fee27a1c35945648a58f9087a714e9d4"
],
"Cmd": [
"python",
"./manage.py",
"runserver",
"0.0.0.0:8003"
],
"Image": "mysite:v5",
"Volumes": null,
"WorkingDir": "/user/local/myapp/mysite",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "75bead260e4c25ced7ebc23bab018dcd9d2b0d9dea92def050e9528c517eae07",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"8003/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8003"
}
]
},
"SandboxKey": "/var/run/docker/netns/75bead260e4c",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "7cdcb22a6b770c30ce0ff39cb4ea4465622975938e1b9264d75e075094c27416",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.5",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:05",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "44a01341c3c54f735e4866da1bc3177eec9825aae501ef31c5bfd898477eb3a5",
"EndpointID": "7cdcb22a6b770c30ce0ff39cb4ea4465622975938e1b9264d75e075094c27416",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.5",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:05",
"DriverOpts": null
}
}
}
}
]
命令持续更新中…