Build a Docker Image

https://github.com/docker/labs/blob/master/developer-tools/java/chapters/ch03-build-image.adoc

  1. 這篇文章介紹瞭如何構架docker鏡像;
  2. 通過dockerfile創建docker鏡像,dockerfile中有相關指令;
  3. 常用命令:
    作用 例子
    ROM Dockerfile中第一條命令
    OPY 拷貝文件到容器指定目錄
    NV 設置環境變量
    UN 執行命令
    MD 執行容器命令
    XPOSE 指定監聽端口
  4. 創建一個目錄hellodocker,創建一個Dockerfile
    FROM ubuntu:latest
    
    CMD ["/bin/echo", "hello world"]
    
  5. 創建鏡像
    docker image build . -t helloworld
    
    輸出

    Sending build context to Docker daemon 2.048kB
    Step 1/2 : FROM ubuntu:latest
    latest: Pulling from library/ubuntu
    9fb6c798fa41: Pull complete
    3b61febd4aef: Pull complete
    9d99b9777eb0: Pull complete
    d010c8cf75d7: Pull complete
    7fac07fb303e: Pull complete
    Digest: sha256:31371c117d65387be2640b8254464102c36c4e23d2abe1f6f4667e47716483f1
    Status: Downloaded newer image for ubuntu:latest
    —> 2d696327ab2e
    Step 2/2 : CMD /bin/echo hello world
    —> Running in 9356a508590c
    —> e61f88f3a0f7
    Removing intermediate container 9356a508590c
    Successfully built e61f88f3a0f7
    Successfully tagged helloworld:latest

  6. 通過查看鏡像,可以看到 docker image list
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    helloworld          latest              e61f88f3a0f7        3 minutes ago       122MB
    ubuntu              latest              2d696327ab2e        4 days ago          122MB
    
  7. 通過命令行創建容器,可以看到輸出了hello world
    docker container run helloworld
    
    輸出:

    hello world

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章