本文来自https://docs.docker.com/docker-for-mac/

1. 安装Docker

https://docs.docker.com/docker-for-mac/install/

2. 安装好以后从应用中双击docker来启动docker,然后MacOS的命令行中也已经可以运行Docker的命令了

3. 查看Docker的版本

$ docker --version
Docker version 18.09, build c97c6d6

$ docker-compose --version
docker-compose version 1.23.2, build 8dd22a9

$ docker-machine --version
docker-machine version 0.16.0, build 9ba6da9

4. 测试Docker有没有安装好,在terminal中执行

$ docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
Status: Downloaded newer image for hello-world:latest

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

  这个命令会自动下载一个hello-world的image然后执行,主要是为了确认你的安装正常

5. 启动一个webserver

$ docker run --detach --publish=80:80 --name=webserver nginx

 然后可以从电脑上打开http://localhost来看,应该能看到nginx的页面

6. 查看正在运行的docker

$ docker container ls
CONTAINER ID   IMAGE   COMMAND                  CREATED              STATUS              PORTS                         NAMES
56f433965490   nginx   "nginx -g 'daemon off"   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp, 443/tcp   webserver

7. 停止和删除这些Docker

$ docker container ls
$ docker container stop webserver
$ docker container ls -a
$ docker container rm webserver
$ docker image ls
$ docker image rm nginx