Docker 入門(Mac環境)-part 1 入門基本操作

weixin_34198881發表於2018-07-09

part-1 入門基本操作

Docker 安裝

  1. 去官網下載對應的版本,然後點選安裝就可以了;
  2. 如果環境是Linux,可以參照之前寫的get started教程

檢視docker版本

  1. docker --version,很多軟體版本都是這樣檢測,很容易記住的。如果打 docker version,會得到更加詳細的資訊
➜  ~ docker --version
Docker version 17.12.0-ce, build c97c6d6
➜  ~ docker version
Client:
 Version:   17.12.0-ce
 API version:   1.35
 Go version:    go1.9.2
 Git commit:    c97c6d6
 Built: Wed Dec 27 20:03:51 2017
 OS/Arch:   darwin/amd64

Server:
 Engine:
  Version:  17.12.0-ce
  API version:  1.35 (minimum version 1.12)
  Go version:   go1.9.2
  Git commit:   c97c6d6
  Built:    Wed Dec 27 20:12:29 2017
  OS/Arch:  linux/amd64
  Experimental: true
  1. docker info會得到比docker version更加詳細的資訊,如下:
➜  ~ docker info
Containers: 2
 Running: 0
 Paused: 0
 Stopped: 2
Images: 1
Server Version: 17.12.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: 89623f28b87a6004d4b785663257362d1658a729
runc version: b2567b37d7b75eb4cf325b77297b140ea686ce8f
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.60-linuxkit-aufs
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.952GiB
Name: linuxkit-025000000001
ID: VSOE:2YDP:C37G:UPUK:6Z47:NMMQ:2HFG:6RQF:IUAA:BJPX:X3QK:PSIL
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 22
 Goroutines: 41
 System Time: 2018-07-09T08:25:19.054780468Z
 EventsListeners: 2
HTTP Proxy: docker.for.mac.http.internal:3128
HTTPS Proxy: docker.for.mac.http.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

檢查Docker的安裝

  1. 可以通過執行一個簡單的docker映象來檢測docker是否安裝成功,命令是很常見的hello world,docker run hello-world
➜  ~ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:3e1764d0f546ceac4565547df2ac4907fe46f007ea229fd7ef2718514bcec35d
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://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/
  1. 可以看到實際上開始機器上並沒有安裝hello-world這個映象,他自動從docker-hub上下載了一個,然後啟動了,下面的文字敘述了一下整個過程,還提示可以再試一下ubuntu的bash,等
  2. 可以使用ls命令來看看本機有哪些映象,docker image ls
➜  ~ docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              e38bc07ac18e        2 months ago        1.85kB
  1. docker container ls可以用來檢視正在執行的容器,加--all引數可以看執行的歷史
➜  ~ docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
➜  ~ docker container ls --all
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
cbcd0f49f39d        hello-world         "/hello"            4 minutes ago       Exited (0) 4 minutes ago                        epic_poincare
14ade628e65a        hello-world         "/hello"            18 minutes ago      Exited (0) 18 minutes ago                       flamboyant_bell
d0a7facb8e31        hello-world         "/hello"            18 minutes ago      Exited (0) 18 minutes ago                       cranky_cray
  1. docker container ls -aq,在清爽模式下檢視所有的程式歷史(all in quiet mode)
➜  ~ docker container ls -aq
cbcd0f49f39d
14ade628e65a
d0a7facb8e31

相關文章