Docker for Mac

2018-07-12  本文已影响0人  华阳_3bcf

Docker installation

方法一

brew cask install docker

速度太慢,放弃。

方法二

从官网下载并安装 https://store.docker.com/editions/community/docker-ce-desktop-mac

安装完成后,在命令行验证

$ docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 18.03.1-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: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.87-linuxkit-aufs
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.952GiB
Name: linuxkit-025000000001
ID: IKPU:M67H:NARD:OSTN:ORBS:HYJO:62CF:ROMP:4S5H:TB4J:WHYP:FP5S
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 21
 Goroutines: 39
 System Time: 2018-07-12T07:58:35.405189215Z
 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 run

docker login

在正式使用之前要 Docker login, 然后才能从registry 下载image。

$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username (xxxxxx@163.com): royzeng
Password:
Login Succeeded

注意:Username 部分不能输入email,而要输入小写的用户名,否则验证失败。

docker run

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9db2ca6ccae0: Pull complete
Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

...

本地没有 image,docker会自动下载,然后再运行。

查看刚刚下载的image:

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              2cb0d9787c4d        32 hours ago        1.85kB

Start a Dockerized web server.

$ docker run -d -p 80:80 --name webserver nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
683abbb4ea60: Pull complete
a470862432e2: Pull complete
977375e58a31: Pull complete
Digest: sha256:a65beb8c90a08b22a9ff6a219c2f363e16c477b6d610da28fe9cba37c2c3a2ac
Status: Downloaded newer image for nginx:latest
b5f38a3b717cf5cc3da5b453104e021ead4d1b01ec210f71c1d430ffe239b9b2

检查

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
b5f38a3b717c        nginx               "nginx -g 'daemon of…"   2 minutes ago       Up 2 minutes        0.0.0.0:80->80/tcp   webserver

$ netstat -an | grep LISTEN | grep 80
tcp4       0      0  *.80                   *.*                    LISTEN

$ curl -s -o /dev/null -w %{http_code} http://localhost:80
200%

$ curl -I http://localhost:80
HTTP/1.1 200 OK
Server: nginx/1.15.1
Date: Thu, 12 Jul 2018 08:38:19 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 03 Jul 2018 13:27:08 GMT
Connection: keep-alive
ETag: "5b3b79ac-264"
Accept-Ranges: bytes

本机打开浏览器,查看 http://localhost

停止服务并删除

$ docker container stop webserver
webserver
$ docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
b5f38a3b717c        nginx               "nginx -g 'daemon of…"   15 minutes ago      Exited (0) 28 seconds ago                       webserver
13fd455d24c3        hello-world         "/hello"                 21 minutes ago      Exited (0) 21 minutes ago                       zealous_panini
$ docker container rm webserver
webserver

$ docker container ls -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
13fd455d24c3        hello-world         "/hello"            23 minutes ago      Exited (0) 23 minutes ago                       zealous_panini

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              2cb0d9787c4d        32 hours ago        1.85kB
nginx               latest              3c5a05123222        5 days ago          109MB

$ docker image rm nginx
Untagged: nginx:latest
Untagged: nginx@sha256:a65beb8c90a08b22a9ff6a219c2f363e16c477b6d610da28fe9cba37c2c3a2ac
Deleted: sha256:3c5a051232223f9ccf4a604d611696e98392648c9e567d3ecd2af881c9f93101
Deleted: sha256:2e64c3f9dc3c0c5768f17267f86846b6fba97792bfd22b6e77a2bf93cd9ccef2
Deleted: sha256:4e235fb8cfa4355abbe18ebc45cf080c7f096cca340df84ec8b4dead162590cc
Deleted: sha256:9c46f426bcb704beffafc951290ee7fe05efddbc7406500e7d0a3785538b8735

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              2cb0d9787c4d        32 hours ago        1.85kB

参考文档:https://docs.docker.com/docker-for-mac/

上一篇下一篇

猜你喜欢

热点阅读