Docker安裝與測試

現在Docker的技術已經非常成熟,在Windows10之後的環境也讓Docker非常容易安裝,在Windows 10下安裝Docker就像是安裝一般的應用程式一樣簡單,只要前往官方網頁,如下所示,下載相對應版本的安裝程式,執行之後即可完成安裝作業(網址:https://www.docker.com/get-started/):

以上述的畫面為例,請先選擇左側的下載按鈕,下載Docker Desktop for Windows,然後再到Docker Hub進行註冊即可。安裝完畢之後,系統的背景會執行一個Docker伺服程序,此時,我們可以開一個命令提示字元(安裝完畢之後重開的才能找到docker指令),利用以下的指令檢查Docker的版本:

docker --version

執行結果如下:

然後執行以下指令測試一切是否有可以正確地執行:

docker run hello-world

如果收到如下所示的訊息,那表示一切功能正常,可以開始使用Docker指令建立或執行容器:

C:\Users\minhuang>docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:80f31da1ac7b312ba29d65080fddf797dd76acfb870e677f390d5acba9741b17
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/get-started/

反之,如果你收到的是這個訊息的話,那就表示Docker的背景程序沒有被順利啟動喔。

C:\Users\minhuang>docker run hello-world
docker: error during connect: This error may indicate that the docker daemon is not running.: Post "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/create": open //./pipe/docker_engine: The system cannot find the file specified.
See 'docker run --help'.

之前所有的Docker指令都需要在命令提示字元才能下達,但是現在有了Docker Desktop之後,有許多工作可以在Docker Desktop中以圖形介面的方式執行,當然這也包括在介面中檢視目前已下載的image,已執行或暫停中的container,以及一些特色image的介紹,如下圖所示:

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *