Copyright, without permission, is prohibited reprint
chapter
- Docker Introduction
- Docker and the difference between virtual machines
- Docker installation
- Docker Hub
- Docker mirror (image)
- Docker container (Container)
- Docker container operations
- Docker container shell
- Docker Dockerfile
- Construction Docker mirror (docker build)
- Docker Dockerfile instruction
- Docker examples
- Docker Compose
- Docker network
In Docker, everything on the mirror, is a combination of a file system and configuration parameters essentially the mirror.
Generally corresponding to a mirror image of an application, for example: a mirror only provides nginx nginx applications instance running image is referred to as a container (image contains the application), a mirror can have multiple instances.
Docker program supports a series of commands, can docker help
see the command.
The following command as an example:
docker run hello-world
run
Docker run a command tells the instance of a mirror image of thathellow-world
application container, if the mirror is not present, download from Docker hub.hello-world
Specification of the Mirror
Let's look at an example of running Busybox mirror:
$ sudo docker run -it --rm busybox
- docker command to be executed with root privileges, so use
sudo
busybox
Is the name of the mirror-it
Represents run in interactive mode--rm
After the container is stopped automatically deleted
This command will download and run busybox mirror, then the system enters busybox sh
terminal.
Mirror mounted display Docker
To see Docker mirror installed on your system, execute the following command.
Simple usage
docker images
Options
-q
- output only image ID
return value
Printing system installed on the mirror list
example
[root@qikegu ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 64f5d945efcc 10 days ago 1.2MB
php 7-fpm d330e525cad6 6 weeks ago 367MB
nginx latest 2bcb04bdb83f 7 weeks ago 109MB
hello-world latest fce289e99eb9 4 months ago 1.84kB
jenkins latest cd14cecfdb3a 10 months ago 696MB
As described above, the mirror has the following properties
- TAG - mirrored labels, similar versions can be specified tag mounting mirrors, each mirror in the docker hub detailed instructions on the label
- Image ID - Mirror ID, a unique logo image
- Created - Created Mirror
- Virtual Size - image size
The following example uses -q
parameters, only the output image ID:
[root@qikegu ~]# docker images -q
64f5d945efcc
502d06d3bfdf
d330e525cad6
2bcb04bdb83f
fce289e99eb9
cd14cecfdb3a
Run Docker Mirror
You can use docker run
the command to run a mirror, if not installed, will start Docker Hub download mirrors.
Simple usage
docker run image
Options
- Image - Specifies the image name / ID.
return value
Download and run the specified image.
example
[root@qikegu ~]# docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Delete Docker Mirror
docker rmi
Command delete docker mirror installed on the system.
Simple usage
docker rmi image
Options
- Image - to remove the mirror (name or ID)
return value
Delete the specified image
example
Delete node Mirror
[root@qikegu ~]# docker rmi 502d06d3bfdf
Untagged: node:latest
Untagged: node@sha256:3d4411d1933dc93e78b9e0de556a22178269952b98cbbea7ca935d890527ae27
Deleted: sha256:502d06d3bfdf8b91c5b0d6db2f36a6da816a374807cdab01edcd1602ec0e8572
Deleted: sha256:bdd7d668ca8f7724e211e1773eb2ff8c4875a525d31eaf74abe3b9d3c2f70d2a
Deleted: sha256:57d08b934ce43d2861a7a44f4136b244b1bca7ecbe5904ab4d04ddae703aa4af
Deleted: sha256:8d8dabce32d508dfcd126ab43cde7b690764c4bd06800e7cac816d367473ad3e
Deleted: sha256:addff6454b75bcccc23ba0cdbf9ff5d83f6df71523cd3428261d1785c3e3c592
Deleted: sha256:dae4f674403b331cb8c19b2c238ffa7d5a7249a1b4fafc4725054201dce3341a
Deleted: sha256:a9a9c8853295275070975beba78ec0f573172e6e41b30232a00d8af0d49b8ef3
Deleted: sha256:ddf0293e8e23246803d265b158ffbb9453d925fe392b43515984815853e9121b
Deleted: sha256:f94641f1fe1f5c42c325652bf55f0513c881c86b620b912b15460e0bca07cc12
docker inspect
This command can view the details of the mirror.
Simple usage
docker inspect image
Options
- Image - mirror name or ID.
return value
Details of an output mirror.
example
[root@qikegu ~]# docker inspect busybox
[
{
"Id": "sha256:64f5d945efcc0f39ab11b3cd4ba403cc9fefe1fa3613123ca016cf3708e8cafb",
"RepoTags": [
"busybox:latest"
],
"RepoDigests": [
"busybox@sha256:4b6ad3a68d34da29bf7c8ccb5d355ba8b4babcad1f99798204e7abb43e54ee3d"
],
"Parent": "",
"Comment": "",
"Created": "2019-05-09T21:19:58.308508481Z",
"Container": "8af67ba15d5afe424a7de8f00dba68d886256ff687e8c01b539d79fcc4a5eb31",
"ContainerConfig": {
"Hostname": "8af67ba15d5a",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"sh\"]"
],
"ArgsEscaped": true,
"Image": "sha256:6d548ae6d7d617ec5ce4cd94c61d0df45d5eeeab5d717398736d14437bb0faa5",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "18.06.1-ce",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"sh"
],
"ArgsEscaped": true,
"Image": "sha256:6d548ae6d7d617ec5ce4cd94c61d0df45d5eeeab5d717398736d14437bb0faa5",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",
"Os": "linux",
"Size": 1199418,
"VirtualSize": 1199418,
"GraphDriver": {
"Data": {
"MergedDir": "/var/lib/docker/overlay2/ca7aa9c486b89ae8b6dce263d7d94702e2597f9e8a873461182 8d7c4a480170c/merged",
"UpperDir": "/var/lib/docker/overlay2/ca7aa9c486b89ae8b6dce263d7d94702e2597f9e8a8734611828 d7c4a480170c/diff",
"WorkDir": "/var/lib/docker/overlay2/ca7aa9c486b89ae8b6dce263d7d94702e2597f9e8a8734611828d 7c4a480170c/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:d1156b98822dccbb924b4e5fe16465a7ecac8bfc81d726177bed403a8e70c972"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
Details of command usage, use
docker help command
to view, for example:docker help rmi