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/engine/userguide/
将文件快照加载到container中,执行指定命令,如 > run hello-wold
重写指定命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
$ docker run busybox echo hi here hi here
$ docker run busybox ls bin dev etc home proc root sys tmp usr var 可以看出打印出的文件目录是运行的linux虚拟机的文件目录
查看运行中的container
1 2 3 4
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 07615c2e850e busybox "ping baidu.com" 19 seconds ago Up 18 seconds confident_feynman
查看所有的container,包含以前运行过的。
1 2 3 4 5 6 7 8 9 10 11
> docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 07615c2e850e busybox "ping baidu.com" About a minute ago Up About a minute confident_feynman a043e6324f01 busybox "ls" 14 hours ago Exited (0) 14 hours ago quirky_hawking a49540a381c4 busybox "echo hi here" 14 hours ago Exited (0) 14 hours ago silly_wozniak 5e8d8cab229d hello-world "/hello" 14 hours ago Exited (0) 14 hours ago confident_poitras 32e394eb48be elasticsearch:6.5.0 "/usr/local/bin/dock…" 2 weeks ago Exited (255) 40 hours ago 0.0.0.0:9200->9200/tcp, 9300/tcp sharp_sanderson 26e7cfd18013 elasticsearch:6.5.0 "/usr/local/bin/dock…" 2 weeks ago Exited (137) 2 weeks ago upbeat_hawking 3aef31dc5086 elasticsearch:6.5.0 "/usr/local/bin/dock…" 2 weeks ago Exited (137) 2 weeks ago trusting_bhabha 813f5b2d17c5 hello-world "/hello" 2 weeks ago Exited (0) 2 weeks ago
docker run
docker run 命令本身运行了两条指令: docker create 以及dokcer start:
//-a的作用是将输出打印到终端中。 $ docker start -a 1a7fc1e876787a20d190187ba0ba6e83eda5f76b0401e9d511d2982f9d8533a6
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/engine/userguide/
$ docker system prune WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all dangling images - all dangling build cache Are you sure you want to continue? [y/N] y Deleted Containers: 1a7fc1e876787a20d190187ba0ba6e83eda5f76b0401e9d511d2982f9d8533a6 a043e6324f01a418a8c115b4b1cdddab0a10afff9bc9c5ee06a720219a4f1b1c a49540a381c4d7da4dfd1efb598a27c2db3574115b82b1b6d33c4f8390b5241e 5e8d8cab229df7f2adcef62f344581fd7e9094fd93e26618d0999545cdc6d66e 32e394eb48be7d5cd7b530a78559ab686f7cf9af88c2c7ae1fdc68e551ca5b36 26e7cfd18013369a5bc8fed0b5612ad2703929f18c01cb50809274dde055ae66 3aef31dc5086b99029e3ecabc2f6ba0cb096000cf9e535d685d08e78de9db692 813f5b2d17c5368e5c1804450da9aa054fe7072d89c64db0a77f347dd6b848ed 0d47fb9e443b4e4630722e41ddcec47fe9d8c8f5488f26f68963ad110acc0601 b0a0dac8a3ed04083591e959d339db4ba8a74cb311f793cbaa98e931e68bd333 bd1c71df5bc48a49308bba863adf66d7c7400fe93936718afbac9c10255f2804 585f744217f723b9c355720abed52bcf87d5bc9c6159c265b88b965922741106 7a3fef3b2896bc383f28cb5f1374763b94c7503827fc5705b35442e842035ce5 ad43464f85fcb2378435bdebbd2cd5c3232af2439bb934f9b0ccc1751d27e297 04a5b4a90ba958d8d3b38d369adb81facd04914535fb77da220792cf011a4963 9102238917d07e0e44a6f052fc6919f3b7b71f55f170918d9c3d5646491277f0 39e50fa4f86b5a260dd472cbfae7a875410093a95bb349e5551156f88b71eb3d 49e7c150cac80467f1eb66ceb2ea53fc06e855f3d7f93f1f41b781b956c071ba 5f5d3dd19fba4734a9b3508f4b0fe9bce5fc3c993c08a29fe2f98e01c622f651 fd9d9e75471a281b1388e9376492b0017055a613b833d40598a95b83d5c4c599 f8564237f6ffc9b95f06bab040aedd465f915f8cc58abdf63fcf8346476cc3ca f48f5791f55949dcbd3c4c010d3336877c9887f0a5a2a0973d1d06ede75f8bfe 3aee61c2515fbcb95e8bbc631450037ed7c31df12084cb18fe6a7fcc44d9ba2f 460336feb3c41a8449edf6938813055f4f1a54bca5ac0d4792ebf56c5b150e43 0175f73a66980a7976484b6165914dc2c92b3038de212ed3c8ada518b3747315 5bb9c44ff6e00236e1efff308c15ab2c325dca83dadcfa5436929fe53bca3c9b
$ docker run redis $ docker exec -it 5f6f2e746bf4 redis-cli 127.0.0.1:6379> set myvalue 5 OK 127.0.0.1:6379> get myvalue "5"
sh在container中执行任意指令
1 2 3 4 5 6 7
$ docker exec -it 5f6f2e746bf4 sh # ls # cd / # ls bin boot data dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var # redis-cli 127.0.0.1:6379>