# 基礎指令
# Image 映像檔 常用指令
指令 | 說明 | 範例 |
---|---|---|
search | 搜尋 | docker search [image_name] |
pull | 下載 | docker pull [image_name] |
images | 查看目前 images (列表) | docker images |
run | 執行 | docker run [-ti] [centos] [/bin/bash] |
rmi [image ID] | 刪除 | docker rmi [615cb40d5d19] |
build | 建立 | docker build [-t project .] |
login | 登入 | docker login [docker.okborn.com] |
push | 上傳 | docker push |
# Container 容器 常用指令
# Registry 倉庫 常用指令
# 基礎指令實作
# 實作目標:
# 實作的流程如下:
# 第一步:
從 Docker Hub 下載 Docker Image 到 local
要下載 Docker Image 之前需要先搜尋一下,Docker Image 的 Name 是什麼,指令如下:
$ docker search ubuntu -f is-official=true
is-official=true
表示要搜尋是官方的 Docker image就選擇星星數最多的 Name 為 ubuntu
找到了 ubuntu 的 Docker Image Name 之後,就可以把此 image pull 下來,指令如下:
$ docker pull ubuntu
執行結果如下圖
要再一次確認 ubuntu 的 docker image 有沒有下載下來,可以使用以下的指令
$ docker images
執行結果如下圖
# 第二步:
有了 Docker Image 之後就可以把 container 執行起來了,並且進入 Docker Container 的 terminal 裡面
指令如下
$ docker run -it -p 8000:80 ubuntu /bin/bash
使用以上的指令就可以進入了 docker container 裡面的 terminal
可以再打開另外一個 terminal 視窗,輸入以下指令
$ docker ps -a
確認 docker container 有正常的執行,如下圖:
# 第三步:
在 docker container 裡面安裝和啟動 apache 的 http service,指令如下:
root@a03f4fc98ea2:/# apt-get update root@a03f4fc98ea2:/# apt-get install -y apache2 root@a03f4fc98ea2:/# service apache2 start
if it is success will show
簡單寫一個 hellowolrd.html 檔案放在 /var/www/html 的路徑下,指令如下:
root@a03f4fc98ea2:/# echo "HelloWorld" > /var/www/html/helloworld.html
使用 cat /etc/hosts 指令查看 docker container 的 IP 如下圖:
如果想要使用 ifconfig 指令,需要安裝 net-tools 工具指令如下:
root@a03f4fc98ea2:/# apt-get install -y net-tools
# 第四步:
# 參考文章
iT邦幫忙/@yangj26952
用簡單的例子來說明如何使用 Docker 指令