-
載入速度與虛擬機器不同,所需的硬體資源很少。
-
在同一作業系統上同時執行多個Docker容器。
-
你可以修改容器並對其進行部署,或將Docker檔案定義提供給朋友,以便在同一環境中工作。
$ docker -v
Docker version 17.12.0-ce-rc2, build f9cde63
$ docker container run alpine echo "Hello World"
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
2fdfe1cd78c2: Pull complete
Digest: sha256:ccba511b...
Status: Downloaded newer image for alpine:latest
Hello World
docker container run alpine echo "Hello World"
Hello World
$ docker container run alpine echo "Hello World"
$ docker container run centos ping -c 5 127.0.0.1
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
85432449fd0f: Pull complete
Digest: sha256:3b1a65e9a05...
Status: Downloaded newer image for centos:latest
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.022 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.019 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.029 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.030 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.029 ms
--- 127.0.0.1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4103ms
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
85432449fd0f: Pull completeDigest: sha256:3b1a65e9a05...Status:
while :
do
wget -qO- https://talaikis.com/api/quotes/random
printf 'n'
sleep 5
done
{"quote":"Martha Stewart is extremely talented. Her designs are picture perfect. Our philosophy is life is messy, and rather than being afraid of those messes we design products that work the way we live.","author":"Kathy Ireland","cat":"design"}{"quote":"We can reach our potential, but to do so, we must reach within ourselves. We must summon the strength, the will, and the faith to move forward - to be bold - to invest in our future.","author":"John Hoeven","cat":"faith"}
$ docker container run -d --name quotes alpine \ /bin/sh -c "while :; do wget -qO- https://talaikis.com/api/quotes/random; printf '\n'; sleep 5; done"
$ docker container ls -l
$ docker container ls
列 | 描述 |
---|---|
Container ID | 唯一的容器 ID 。它是SHA-256. |
Image | 所以用的映象 |
Status | 容器的狀態(created,restarting,running,removing,paused,exited,or dead) |
Ports | 對映到宿主機的埠 |
Names | 分配到容器的名字 (可以是多個名字的) |
$ docker container ls -a
$ docker container ls -q
$ docker container rm -f $(docker container ls -a -q)
$ docker container ls -h
$ docker container run -d --name quotes alpine \ /bin/sh -c "while :; do wget -qO- https://talaikis.com/api/quotes/random; printf '\n'; sleep 5; done"
$ docker container stop quotes
$ export CONTAINER_ID = $(docker container ls | grep quotes | awk '{print $1}')
$ docker container stop $CONTAINER_ID
$ docker container rm <container ID>
$ docker container rm <container name>
-
https://talaikis.com/random_quotes_api/
-
https://amzn.to/2LgQZmN