下載Docker
鏈接:https://www.docker.com/community-edition
需要先註冊才能下載,註冊時因爲有谷歌人機驗證需要翻牆。怕麻煩或不會弄的可以直接我放在百度雲盤的Docker。
鏈接:https://pan.baidu.com/s/11JJ0xpuCU7MANr1k6OF87A 密碼:raq7
安裝Docker
安裝按提示步驟可以順利安裝。
檢查Docker版本
確保您的docker、docker-compose和docker-machine版本是最新的,並且與Docker.app兼容。如果運行不同的版本,輸出可能會有所不同。
$ docker --version
Docker version 18.03.1-ce, build 9ee9f40
$ docker-compose --version
docker-compose version 1.21.1, build 5a3f1a3
$ docker-machine --version
docker-machine version 0.14.0, build 89b8332
驗證Docker
打開一個命令行終端,通過運行簡單的Docker映像hello-world來測試您的安裝是否有效:
啓動Dockerized Web服務器。如果在本地找不到鏡像,Docker會從Docker Hub中取出它。
- 執行報錯了
docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: unauthorized: incorrect username or password.
See 'docker run --help'.
修改成國內源
vim daemon.json
# 增加
"registry-mirrors": ["https://registry.docker-cn.com"]
重啓Docker
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.
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/
Docker基本使用方法
- 查看容器的詳細信息
docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 使用以下命令停止並刪除容器和圖像。使用“all”標誌(–all或-a)查看已停止的容器。
$ docker container ls
$ docker container stop webserver
$ docker container ls -a
$ docker container rm webserver
$ docker image ls
$ docker image rm hello-world
詳細見官方文檔
https://docs.docker.com/docker-for-mac/#add-client-certificates