博客 / 詳情

返回

Y 分鐘速成 docker

源代碼下載: docker-cn.bat

:: 下載、安裝、運行 hello-world 鏡像(image)
docker run hello-world

:: :: 如果這是第一次運行,你應該能見到這些信息
:: Unable to find image 'hello-world:latest' locally # 在本地找不到鏡像xxx
:: latest: Pulling from library/hello-world
:: 1b930d010525: Pull complete
::   Digest: sha256:4fe721ccc2e8dc7362278a29dc660d833570ec2682f4e4194f4ee23e415e1064
:: Status: Downloaded newer image for hello-world:latest
::
:: Hello from Docker! # 來自Docker的歡迎
:: This message shows that your installation appears to be working correctly. # 此信息表明你的安裝似乎成功了
::
:: To generate this message, Docker took the following steps: # Docker進行了如下步驟來產生此信息
:: 1. The Docker client contacted the Docker daemon. # Docker客户端聯繫Docker守護程序
:: 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. # Docker守護程序從Docker Hub拉取鏡像
::     (amd64)
:: 3. The Docker daemon created a new container from that image which runs the # Docker守護程序從鏡像中創建了一個容器
::     executable that produces the output you are currently reading. # 運行了產生你正在讀的輸出的可執行文件
:: 4. The Docker daemon streamed that output to the Docker client, which sent it # Docker守護程序把輸出流式傳輸給Docker客户端,後者發送到你的終端上
::     to your terminal.
::
:: To try something more ambitious, you can run an Ubuntu container with: # 若要嘗試更強大的東西,你可以用該命令運行Ubuntu容器
::  $ docker run -it ubuntu bash
::
:: Share images, automate workflows, and more with a free Docker ID: # 使用免費的Docker ID來分享鏡像,自動化工作流等
::  https://hub.docker.com/
::
:: For more examples and ideas, visit: # 欲獲取更多例子和想法,訪問
:: https://docs.docker.com/get-started/

:: 現在來看看當前正運行的鏡像
docker ps
:: CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS
::   NAMES

:: 看看之前運行過的鏡像
docker ps -a

:: CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS
::          NAMES
:: 4a76281f9c53        hello-world         "/hello"            2 minutes ago       Exited (0) 2 minutes ago
::          happy_poincare
:: 名字(name)是自動生成的,因此它會和你的不同

:: 移除(remove)我們之前生成的鏡像
docker rm happy_poincare

:: 測試是否真的刪除了
docker ps -a
:: CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS
::   NAMES

:: 為容器(container)指定自定義名字
docker run --name test_container hello-world
:: 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 ps -a
:: CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                         PORTS
::               NAMES
:: d345fe1a4f41        hello-world         "/hello"            About a minute ago   Exited (0) About a minute ago
::                test_container
:: 如你所見,名字現在是我們指定的了

:: 從命名過的容器中獲取日誌(logs)
docker logs test_container
:: 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 rm test_container

docker run ubuntu
::  Unable to find image 'ubuntu:latest' locally
::  latest: Pulling from library/ubuntu
::  2746a4a261c9: Pull complete
::                                                        4c1d20cdee96: Pull complete                                                                                                                                                 0d3160e1d0de: Pull complete                                                                                                                                                 c8e37668deea: Pull complete                                                                                                                                                 Digest: sha256:250cc6f3f3ffc5cdaa9d8f4946ac79821aafb4d3afc93928f0de9336eba21aa4
::  Status: Downloaded newer image for ubuntu:latest

docker ps -a
::  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS
::           NAMES
::  c19e9e5b000a        ubuntu              "/bin/bash"         5 seconds ago       Exited (0) 4 seconds ago
::           relaxed_nobel

::  在交互模式(interactive mode)下運行容器
docker run -it ubuntu
::  root@e2cac48323d2:/# uname
::  Linux
::  root@e2cac48323d2:/# exit
::  exit

docker rm relaxed_nobel

docker ps -a
:: CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                          PORTS
::               NAMES
:: e2cac48323d2        ubuntu              "/bin/bash"         2 minutes ago       Exited (0) About a minute ago
::               nifty_goldwasser

docker rm nifty_goldwasser

有建議?或者發現什麼錯誤?在Github上開一個 issue ,或者發起 pull request !


原著Ruslan López,並由 0 個好心人修改。
© 2022 Ruslan López
Translated by: imba-tjd
本作品採用 CC BY-SA 3.0 協議進行許可。

user avatar mofaboshi 頭像 caideheirenyagao 頭像
2 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.