- 《Win10上使用Docker【一】》:Docker在Win10上的部署方法
- 《Win10上使用Docker【二】》:Docker的基本使用方法
- 《Win10上使用Docker【三】》:Docker設置
常用操作
查看版本
PS C:\Users\HD> docker version
Client:
Version: 17.09.0-ce
API version: 1.32
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:40:09 2017
OS/Arch: windows/amd64
Server:
Version: 17.09.0-ce
API version: 1.32 (minimum version 1.12)
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:45:38 2017
OS/Arch: linux/amd64
Experimental: true
PS C:\Users\HD> docker-compose version
docker-compose version 1.16.1, build 6d1ac219
docker-py version: 2.5.1
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.2j 26 Sep 2016
PS C:\Users\HD> docker-machine version
docker-machine.exe version 0.12.2, build 9371605
查看docker配置詳情
PS C:\Users\HD> docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 17.09.0-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.9.49-moby
Operating System: Alpine Linux v3.5
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.934GiB
Name: moby
ID: NT5B:UFPG:2QMO:ZVDJ:T5KH:J3WW:6NQX:6GXV:YDCG:GYPO:V2ZR:WAHP
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
File Descriptors: 16
Goroutines: 25
System Time: 2017-12-03T07:45:16.3582305Z
EventsListeners: 0
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
查看已創建容器
PS C:\Users\HD> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
我這里沒有數據,是因為剛剛部署好環境,還沒有創建過
拉取 hello-world 鏡像并運行一個容器
執行命令:docker run hello-world ,會默認從Docker Hub拉去鏡像 hello-world,并使用該鏡像運行一個容器
PS C:\Users\HD> docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:150f6d05b8898b79f55114991c01b89688a02dab6115e402b7855792a440caff
Status: Downloaded newer image for hello-world:latest
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://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
運行一個 Ubuntu 容器
PS C:\Users\HD> docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
660c48dd555d: Pull complete
4c7380416e78: Pull complete
421e436b5f80: Pull complete
e4ce6c3651b3: Pull complete
be588e74bd34: Pull complete
Digest: sha256:7c67a2206d3c04703e5c23518707bdd4916c057562dd51c74b99b2ba26af0f79
Status: Downloaded newer image for ubuntu:latest
// 進入容器里面,執行命令 ls
root@afc658251a9c:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
上面的命令下載并啟動了 ubuntu 容器鏡像
啟動一個容器化的 Nginx 服務器
PS C:\Users\HD> docker run -d -p 80:80 --name webserver nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
bc95e04b23c0: Pull complete
f3186e650f4e: Pull complete
9ac7d6621708: Pull complete
Digest: sha256:b81f317384d7388708a498555c28a7cce778a8f291d90021208b3eba3fe74887
Status: Downloaded newer image for nginx:latest
4c0a14eae6bd2fa2f5e93d391118c79d4fe9d0fa9ac08b4ac45964a694aa19cb
通過瀏覽器訪問 80 端口,即可看到剛剛啟動的 nginx
image.png
查看當前已創建的容器
PS C:\Users\HD> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4c0a14eae6bd nginx "nginx -g 'daemon ..." 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp webservers
停止/刪除 容器/鏡像
上一步啟動的 nginx 服務器,在你停止或移除這個容器前,會一直在80端口運行下去
停止命令:docker stop webserver
啟動命令:docker start webserver.
停止并移除容器命令:docker rm -f webserver
查看鏡像
查看本地鏡像:docker images
PS C:\Users\HD> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 9e7424e5dbae 10 days ago 108MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
刪除本地鏡像:docker rmi <image ID | image name>
刪除nginx鏡像:docker rmi nginx