使用 Dockfile 建立映像檔

  1. 在工作目錄產生 index.html。
    [root@dyw219 newimg]# echo 'myweb test' > index.html
    [root@dyw219 newimg]# cat index.html 
    myweb test
    
  2. 建立 Dockerfile,將測試用的 index.html 複製到映像檔 centos/httpd 的網頁根目錄 /var/www/html。
    [root@dyw219 newimg]# vim Dockerfile 
    [root@dyw219 newimg]# cat Dockerfile
    # index.html comment
    FROM centos/httpd:latest
    COPY index.html /var/www/html/
    RUN chmod 644 /var/www/html/index.html
    
  3. docker build 使用 Dockerfile,建立一名為 centos/httpd:index 的映像檔,最後的點 . 表示目前的工作目錄,也可以用絕對目徑。
    [root@dyw219 newimg]# docker build -t centos/httpd:index .
    Sending build context to Docker daemon  5.12 kB
    Sending build context to Docker daemon 
    Step 0 : FROM centos/httpd:latest
     ---> b4650389df73
    Step 1 : COPY index.html /var/www/html/
     ---> b98ddcfe17b5
    Removing intermediate container bd818bc1ef9c
    Step 2 : RUN chmod 644 /var/www/html/index.html
     ---> Running in 816153a21ab4
     ---> eec966fc2c86
    Removing intermediate container 816153a21ab4
    Successfully built eec966fc2c86