天天看點

基于Dockerfile建立一個最簡單的docker鏡像

試着建立一個docker image, 不在乎實用性和功能,隻是對docker 建立image 有個大概的了解,是以有此文章。

文章目錄

  • ​​step1. 建立檔案夾​​
  • ​​step2. 進入檔案夾​​
  • ​​step3. 建立Dockerfile​​
  • ​​step4. 建構鏡像​​

step1. 建立檔案夾

mkdir      

step2. 進入檔案夾

cd      

step3. 建立Dockerfile

vim Dockerfile,  寫入以下内容      
FROM busybox:latest
LABEL tester docker_user<[email protected]>
RUN echo 'hello docker'      

step4. 建構鏡像

docker build -t docker_test -t busybox_test:1.0.0 /app/busybox      
[root@localhost busybox]# docker build -t docker_test -t busybox_test:1.0.0 /app/busybox
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM busybox:latest
latest: Pulling from library/busybox
ea97eb0eb3ec: Pull complete 
Digest: sha256:bde48e1751173b709090c2539fdf12d6ba64e88ec7a4301591227ce925f3c678
Status: Downloaded newer image for busybox:latest
 ---> 219ee5171f80
Step 2/3 : LABEL tester docker_user<[email protected]>
 ---> Running in 94f14af4ef3f
Removing intermediate container 94f14af4ef3f
 ---> 9028fef7e34b
Step 3/3 : RUN echo 'hello docker'
 ---> Running in aaed8574d213
hello docker
Removing intermediate container aaed8574d213
 --->      
[root@localhost busybox]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
busybox_test                    1.0.0               754228d7562e        49 seconds ago      1.23MB
docker_test                     latest              754228d7562e        49 seconds ago      1.23MB
goharbor/chartmuseum-photon     v2.1.2              957cad6ee4f4        2 weeks ago         172MB
goharbor/redis-photon           v2.1.2              ab361cc80013        2 weeks ago         68.8MB
goharbor/trivy-adapter-photon   v2.1.2              396c0a289a68        2 weeks ago         106MB
goharbor/clair-adapter-photon   v2.1.2              b43551e703c2        2 weeks ago         58MB
goharbor/clair-photon           v2.1.2              0e9f86b78780        2 weeks ago         168MB
goharbor/notary-server-photon   v2.1.2              ca212469d8d7        2 weeks ago         104MB
goharbor/notary-signer-photon   v2.1.2              cf87adab9022        2 weeks ago         101MB
goharbor/harbor-registryctl     v2.1.2              da26ae6a8d51        2 weeks ago         132MB
goharbor/registry-photon        v2.1.2              417d60a20a94        2 weeks ago         80.1MB
goharbor/nginx-photon           v2.1.2              f9ea32db995f        2 weeks ago         40.1MB
goharbor/harbor-log             v2.1.2              7514c453345e        2 weeks ago         106MB
goharbor/harbor-jobservice      v2.1.2              123382c0d590        2 weeks ago         169MB
goharbor/harbor-core            v2.1.2              46211d9a0f44        2 weeks ago         150MB
goharbor/harbor-portal          v2.1.2              6eedd3daad4c        2 weeks ago         49.5MB
goharbor/harbor-db              v2.1.2              f0c14faef5d5        2 weeks ago         172MB
goharbor/prepare                v2.1.2              cc5f5219b08b        2 weeks ago         161MB
busybox                         latest              219ee5171f80        3 weeks ago         1.23MB
[root@localhost busybox]#