下载链接https://docs.docker.com/docker-for-mac/
可以选择Stable or Beta版
就是普通安装方法……
将Docker拖到Application中
然后它会要求你输入密码以获得更高的权限,输入密码即可~~
打开docker后,状态栏中可以看到docker的标志,点开会有“Docker is running”的字样,便可以在终端操作
检查docker版本,以保证你的版本较新可用
feiqianyousadeMacBook-Pro:~ yousa$ docker --version
Docker version 1.12.5, build 7392c3b
feiqianyousadeMacBook-Pro:~ yousa$ docker-compose --version
docker-compose version 1.9.0, build 2585387
feiqianyousadeMacBook-Pro:~ yousa$ docker-machine --version
docker-machine version 0.8.2, build e18a919
feiqianyousadeMacBook-Pro:~ yousa$
可以执行类似于上面docker version
命令,或者譬如docker ps
或 docker run hello-world
命令检查docker运行是否正确
docker ps
feiqianyousadeMacBook-Pro:~ yousa$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker run hello-world
如果之前没有下载过这个镜像,会先进行下载该镜像
feiqianyousadeMacBook-Pro:~ yousa$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
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.
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 Hub account:
https://hub.docker.com
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
feiqianyousadeMacBook-Pro:~ yousa$
使用docker启动nginx web服务器
docker run -d -p 80:80 --name webserver nginx
可以使用命令docker ps
查看container运行状态
feiqianyousadeMacBook-Pro:~ yousa$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cae2bd7ae1de nginx "nginx -g 'daemon off" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp, 443/tcp webserver
登录自己web浏览器,输入地址http://localhost/
有如下打印则说明启动ok
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
执行docker stop webserver
即可停止该容器运行,如果需要启动,则执行docker start webserver
即可
一个停止的容器docker ps
是无法查看到的,需要用docker ps -a
执行docker rm -f webserver
这样会删除名为webserver的这个容器
feiqianyousadeMacBook-Pro:~ yousa$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cae2bd7ae1de nginx "nginx -g 'daemon off" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp, 443/tcp webserver
feiqianyousadeMacBook-Pro:~ yousa$ docker stop webserver
webserver
feiqianyousadeMacBook-Pro:~ yousa$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
feiqianyousadeMacBook-Pro:~ yousa$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cae2bd7ae1de nginx "nginx -g 'daemon off" 7 minutes ago Exited (0) 8 seconds ago webserver
d6c2f5b68850 hello-world "/hello" 13 minutes ago Exited (0) 13 minutes ago distracted_bartik
feiqianyousadeMacBook-Pro:~ yousa$ docker start webserver
webserver
feiqianyousadeMacBook-Pro:~ yousa$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cae2bd7ae1de nginx "nginx -g 'daemon off" 8 minutes ago Up 3 seconds 0.0.0.0:80->80/tcp, 443/tcp webserver
feiqianyousadeMacBook-Pro:~ yousa$ docker rm -f webserver
webserver
feiqianyousadeMacBook-Pro:~ yousa$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d6c2f5b68850 hello-world "/hello" 13 minutes ago Exited (0) 13 minutes ago distracted_bartik
feiqianyousadeMacBook-Pro:~ yousa$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d6c2f5b68850 hello-world "/hello" 13 minutes ago Exited (0) 13 minutes ago distracted_bartik
真的很快速……省事