Docker容器安裝方法
阿新 • • 發佈:2019-01-09
下載Docker
安裝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