目錄
Dockerfile
基本結構
指令
創建鏡像(centos版)
創建鏡像(alpine版)
基本結構
Dockerfile 是一個文本格式的配置文件,用戶可以使用 Dockerfile 快速創建自定義鏡像。
Dockerfile 由一行行命令語句組成,并且支持以 # 開頭的注釋行。
Docker分為四部分:
基礎鏡像信息
維護者信息
鏡像操作指令
容器啟動時默認要執行的指令
例如:
# 第一行必須指定基于的基礎鏡像 FROM centos # 維護者信息 LABEL MANTAINER "lvnanhai66 1@36.com" # 鏡像操作指令 RUN useradd -r -M -s /sbin/nologin apache # 容器啟動時默認要執行的指令 CMD ["/usr/local/apache/bin/httpd","-D","FOREGROUND"]
其中,一開始必須指明所基于的鏡像名稱,接下來一般會說明維護者信息。
后面則是鏡像操作指令,例如RUN指令,RUN指令將對鏡像執行跟隨的命令。每運行一條RUN指令,鏡像添加新的一層,并提交。
最后是CMD指令來指定運行容器時的操作指令。
指令
指令的一般格式為INSTRUCTION arguments,指令包括:
FROM
LABEL MAINTAINER
RUN
CMD
EXPOSE
ENV
ADD
COPY
ENTRYPOINT
VOLUME
USER
WORKDIR
ONBUILD
FROM
功能為指定基礎鏡像,并且必須是第一條指令。
如果不以任何鏡像為基礎,那么寫法為:FROM scratch。
同時意味著接下來所寫的指令將作為鏡像的第一層開始
FROM centos //基于centos的鏡像 語法: FROMFROM : FROM : 三種選項,其中 和 是可選項,如果沒有選擇那么默認就是latest
LABEL MAINTAINER
指定維護者信息
語法:LABEL MAINTAINERLABEL MANTAINER "lvnanhai66 1@36.com"
RUN
功能為運行指定的命令
RUN命令有兩種格式
1.RUN command
2.RUN ["executable", "param1", "param2"]
前者將在shell終端中運行命令,即/bin/sh -c;后者則使用exec執行。指定使用其他終端可以通過第二種方式實現,例如:RUN ["/bin/bash","-c","echo hello"]
每條RUN指令將在當前鏡像基礎上執行指定命令,并提交為新的鏡像。當命令較長時可以使用 來換行
[root@localhost ~]# cd httpd/ [root@localhost httpd]# ls Dockerfile files [root@localhost httpd]# vim Dockerfile [root@localhost httpd]# cat Dockerfile FROM busybox LABEL MANTAINER "lvnanhai66 1@36.com" RUN echo "hello lnh" > /tmp/abc [root@localhost httpd]# podman build -t httpd:1.0 . STEP 1/3: FROM busybox STEP 2/3: LABEL MANTAINER "lvnanhai66 1@36.com" --> d761206551e STEP 3/3: RUN echo "hello lnh" > /tmp/abc COMMIT httpd:1.0 --> 80125d342c8 Successfully tagged localhost/httpd:1.0 80125d342c8d86708b7c9a572ea46876a361a2c6a6b21c6b4ad66c4c00dd0b37 [root@localhost httpd]# podman run -it --rm httpd:1.0 /bin/sh / # cd /tmp/ /tmp # ls abc
CMD
CMD支持三種格式:
1.CMD ["executable","param1","param2"]使用exec執行,推薦方式
2.CMD command param1 param2在/bin/sh中執行,提供給需要交互的應用
3.CMD ["param1","param2"]提供給ENTRYPOINT的默認參數
CMD用于指定啟動容器時默認要執行的命令,每個Dockerfile只能有一條CMD命令。如果指定了多條命令,只有最后一條會被執行。
如果用戶啟動容器時指定了運行的命令,則會覆蓋掉CMD指定的命令。
不要把RUN和CMD搞混了。
RUN是構件容器時就運行的命令以及提交運行結果
CMD是容器啟動時執行的命令,在構件時并不運行,構件時緊緊指定了這個命令到底是個什么樣子
CMD ["/usr/local/apache/bin/httpd","-D","FOREGROUND"]
EXPOSE
格式為EXPOSE port [port...]。
例如:
EXPOSE 22 80 8443
EXPOSE用于告訴Docker服務器容器暴露的端口號,供互聯系統使用。
在啟動容器時通過-P,Docker主機會自動分配一個端口轉發到指定的端口;
使用-p則可以具體指定哪個本地端口映射過來。
ENV
格式為ENV key value 。指定一個環境變量,會被后續RUN指令使用,并在容器運行時保持。
ENV PATH /usr/local/apache/bin:$PATH //配置環境變量
ADD
格式為ADD src dest
該命令將復制指定的src到容器中的dest。其中src可以是Dockerfile所在目錄的一個相對路徑(文件或目錄);也可以是一個URL;還可以是一個tar文件(會自動解壓為目錄)。
[root@localhost httpd]# ls Dockerfile files [root@localhost httpd]# ls files/ apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz entrypoint.sh httpd-2.4.54.tar.gz [root@localhost httpd]# vim Dockerfile [root@localhost httpd]# cat Dockerfile FROM busybox ADD files/apr-1.7.0.tar.gz /tmp/ [root@localhost httpd]# podman build -t httpd:2.0 . STEP 1/2: FROM busybox STEP 2/2: ADD files/apr-1.7.0.tar.gz /tmp/ COMMIT httpd:2.0 --> 5a9f6d599dc Successfully tagged localhost/httpd:2.0 5a9f6d599dc3245e3bfba5877bd84f155d9410e1fff6a679a8ebab954f530f1a [root@localhost httpd]# podman run -it --rm httpd:2.0 /bin/sh / # cd tmp/ /tmp # ls apr-1.7.0 /tmp #
COPY
格式為COPY。 復制本地主機的 (為Dockerfile所在目錄的相對路徑,文件或目錄)為容器中的 。目標路徑不存在時會自動創建。 當使用本地目錄為源目錄時,推薦使用COPY。
ENTRYPOINT
ENTRYPOINT有兩種格式:
ENTRYPOINT ["executable","param1","param2"]
ENTRYPOINT command param1 param2(在shell中執行)
配置容器啟動后執行的命令,并且不可被docker run提供的參數覆蓋。而且,如果在docker run的后面提供了參數,這些命令行參數會被當作參數傳遞給ENTRYPOINT指定的程序。
每個Dockerfile中只能有一個ENTRYPOINT,當指定多個ENTRYPOINT時,只有最后一個生效。
例如:ENTRYPOINT ["/bin/bash","/entrypoint.sh"]
VOLUME
格式為VOLUME ["/data"]。
創建一個可以從本地主機或其他容器掛載的掛載點,一般用來存放數據庫和需要保持的數據等
USER
格式為USER daemon。
指定運行容器時的用戶名或UID,后續的RUN也會使用指定用戶。
當服務不需要管理員權限時,可以通過該命令指定運行用戶。并且可以在之前創建所需要的用戶,例如:
RUN groupadd -r postgres && useradd -r -g postgres postgres
要臨時獲取管理員權限可以使用gosu,而不推薦sudo。如果不指定,容器默認是root運行。
WORKDIR
語法:
WORKDIR /path/to/workdir
設置工作目錄,對RUN,CMD,ENTRYPOINT,COPY,ADD生效。如果不存在則會創建,也可以設置多次。
如:
WORKDIR /a WORKDIR b WORKDIR c RUN pwd
pwd執行的結果是/a/b/c
WORKDIR也可以解析環境變量
如:
ENV DIRPATH /path WORKDIR $DIRPATH/$DIRNAME RUN pwd
pwd的執行結果是/path/$DIRNAME
ONBUILD
格式為ONBUILD [INSTRUCTION]。
配置當所創建的鏡像作為其他鏡像的基礎鏡像時,所執行的操作指令。
例如,Dockerfile使用如下的內容創建了鏡像image-A
[...] ONBUILD ADD . /app/src ONBUILD RUN /usr/local/bin/python-build --dir /app/src [...]
此時,如果基于image-A創建新的鏡像時,新的Dockerfile中使用FROM image-A指定基礎鏡像時,會自動執行ONBUILD指令的內容,等價于在后面添加了兩條指令。
FROM image-A # Automatically run the following ADD . /app/src RUN /usr/local/bin/python-build --dir /app/src
使用ONBUILD指令的鏡像,推薦在標簽中注明,例如ruby:1.9-onbuild。
創建鏡像(centos版)
用podman進行dockefile做一個httpd編譯安裝的鏡像,要求要控制版本號,要用到dockerfile中大部分指令及用腳本方式啟動程序,上傳到官方鏡像倉庫
[root@localhost ~]# mkdir httpd [root@localhost ~]# cd httpd/ [root@localhost httpd]# touch Dockerfile [root@localhost httpd]# mkdir files [root@localhost httpd]# ls Dockerfile files //創建一個目錄,在這個目錄下面創建一個Dockerfile文件和存放安裝包的目錄files [root@localhost httpd]# cd files/ [root@localhost files]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz [root@localhost files]# ls apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz //下載安裝包 [root@localhost files]# vim entrypoint.sh [root@localhost files]# cat entrypoint.sh #!/bin/bash sed -i '/^#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf exec "$@" [root@localhost files]# chmod +x entrypoint.sh //賦予腳本執行權限 [root@localhost files]# ll total 11136 -rw-r--r--. 1 root root 1093896 Apr 5 2019 apr-1.7.0.tar.gz -rw-r--r--. 1 root root 554301 Oct 23 2017 apr-util-1.6.1.tar.gz -rwxr-xr-x. 1 root root 88 Aug 30 16:43 entrypoint.sh -rw-r--r--. 1 root root 9743277 Jun 8 16:42 httpd-2.4.54.tar.gz //寫一個腳本作為啟動程序 [root@localhost files]# cd .. [root@localhost httpd]# ls Dockerfile files [root@localhost httpd]# vim Dockerfile [root@localhost httpd]# cat Dockerfile FROM centos LABEL MANTAINER "lvnanhai66 1@36.com" ENV apache_version 2.4.54 //apache版本號 ENV PATH /usr/local/apache/bin:$PATH //配置環境變量 ADD files/apr-1.7.0.tar.gz /usr/src/ ADD files/apr-util-1.6.1.tar.gz /usr/src/ ADD files/httpd-${apache_version}.tar.gz /usr/src/ //這樣可以更換 ADD files/entrypoint.sh / //將這個腳本放到根下面 RUN useradd -r -M -s /sbin/nologin apache && cd /etc/yum.repos.d && rm -r * && curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo && sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo && yum clean all && yum makecache && yum -y install gcc gcc-c++ make openssl-devel pcre-devel expat-devel libtool && cd /usr/src/apr-1.7.0 && sed -i '/$RM "$cfgfile"/d' configure && ./configure --prefix=/usr/local/apr && make && make install && cd ../apr-util-1.6.1 && ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install && cd ../httpd-${apache_version} && ./configure --prefix=/usr/local/apache --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork && make && make install && yum clean all && //清除緩存 yum -y remove gcc gcc-c++ make && //這些編譯工具可以清除 rm -rf /tmp/* /usr/src/* //這個下面的文件可以清除 EXPOSE 80 //映射的端口號 WORKDIR /usr/local/apache //相當于cd這個目錄 CMD ["/usr/local/apache/bin/httpd","-D","FOREGROUND"] //此處加了絕對路徑 ENTRYPOINT ["/bin/bash","/entrypoint.sh"] //不知道有沒有權限,可以直接加bin/bash [root@localhost httpd]# podman build -t httpd:v3.0 . .... STEP 13/13: ENTRYPOINT ["/bin/bash","/entrypoint.sh"] COMMIT httpd:v3.0 --> f65d0bb9ee1 Successfully tagged localhost/httpd:v3.0 f65d0bb9ee17efdffdb53dc52fb92188aaa5fa1ea90cc11e2939855ba71f8ec3 讓這個鏡像運行一個容器進行測試: [root@localhost httpd]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/httpd v3.0 f65d0bb9ee17 About a minute ago 405 MB docker.io/library/httpd latest dabbfbe0c57b 8 months ago 148 MB quay.io/centos/centos latest 300e315adb2f 21 months ago 217 MB [root@localhost httpd]# podman run -d httpd:v3.0 fcf786713d9b55793b997cc98e3571535b1fd4c0553409f3bb18bfd9d51fd234 [root@localhost httpd]# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fcf786713d9b localhost/httpd:v3.0 /usr/local/apache... 4 seconds ago Up 4 seconds ago xenodochial_morse [root@localhost httpd]# podman inspect -l |grep -i ipaddr //過濾查看ip "IPAddress": "10.88.0.6", "IPAddress": "10.88.0.6", [root@localhost httpd]# curl 10.88.0.6 //訪問成功It works!
上傳鏡像: [root@localhost httpd]# podman tag httpd:v3.0 docker.io/lvnanhai66/httpd:v3.0 [root@localhost httpd]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/httpd v3.0 f65d0bb9ee17 8 minutes ago 405 MB docker.io/lvnanhai66/httpd v3.0 f65d0bb9ee17 8 minutes ago 405 MB docker.io/library/httpd latest dabbfbe0c57b 8 months ago 148 MB quay.io/centos/centos latest 300e315adb2f 21 months ago 217 MB [root@localhost httpd]# podman login docker.io Username: lvnanhai66 Password: Login Succeeded! [root@localhost httpd]# podman push docker.io/lvnanhai66/httpd:v3.0 Getting image source signatures Copying blob 3f49a2cae693 done Copying blob 90fc92241475 done Copying blob 8cfba8022d3f done Copying blob 34214738da46 done Copying blob bea1ef732da4 done Copying blob 2653d992f4ef done Copying config f65d0bb9ee done Writing manifest to image destination Storing signatures
拉取自己的鏡像運行容器: [root@localhost ~]# podman run -d --name web -P docker.io/lvnanhai66/httpd:v3.0 Trying to pull docker.io/lvnanhai66/httpd:v3.0... Getting image source signatures Copying blob 929704506730 skipped: already exists Copying blob 26ad906b0de6 done Copying blob c63ffcca07e0 done Copying blob 45fdf32689c6 done Copying blob 0b040dd24d11 done Copying blob 841f6f1ffedd done Copying config f65d0bb9ee done Writing manifest to image destination Storing signatures 4d770508e2552c6ab554079fccf9e72ed79ed43ffcad5d6564d2cac3a07527d6 [root@localhost ~]# podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4d770508e255 docker.io/lvnanhai66/httpd:v3.0 /usr/local/apache... 8 seconds ago Up 8 seconds ago 0.0.0.0:40607->80/tcp web [root@localhost ~]# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4d770508e255 docker.io/lvnanhai66/httpd:v3.0 /usr/local/apache... 19 seconds ago Up 19 seconds ago 0.0.0.0:40607->80/tcp web //如果發現拉取不下來可以加加速器進行注釋(cd /etc/containers/然后vim registries.conf)
創建鏡像(alpine版)
用podman進行dockefile做一個httpd編譯安裝的鏡像,要求要控制版本號,要用到dockerfile中大部分指令及用腳本方式啟動程序,上傳到官方鏡像倉庫,基于alpine鏡像進行dockerfile,使其大小在70M以內
Alpinel 編譯軟件注意事項
[root@localhost ~]# mkdir httpd [root@localhost ~]# cd httpd/ [root@localhost httpd]# touch Dockerfile [root@localhost httpd]# mkdir files [root@localhost httpd]# ls Dockerfile files //創建一個目錄,在這個目錄下面創建一個Dockerfile文件和存放安裝包的目錄files [root@localhost httpd]# cd files/ [root@localhost files]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz [root@localhost files]# ls apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz //下載安裝包 [root@localhost files]# vim entrypoint.sh [root@localhost files]# cat entrypoint.sh #!/bin/bash sed -i '/^#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf exec "$@" [root@localhost files]# chmod +x entrypoint.sh //賦予腳本執行權限 [root@localhost files]# ll total 11136 -rw-r--r--. 1 root root 1093896 Apr 5 2019 apr-1.7.0.tar.gz -rw-r--r--. 1 root root 554301 Oct 23 2017 apr-util-1.6.1.tar.gz -rwxr-xr-x. 1 root root 88 Aug 31 22:38 entrypoint.sh -rw-r--r--. 1 root root 9743277 Jun 8 16:42 httpd-2.4.54.tar.gz //寫一個腳本作為啟動程序 [root@localhost files]# cd .. [root@localhost httpd]# ls Dockerfile files 編寫dockerfile: [root@localhost httpd]# vim Dockerfile [root@localhost httpd]# cat Dockerfile FROM alpine LABEL MANTAINER "lvnanhai66 1@36.com" ENV apr_version=1.7.0 apr_util_version=1.6.1 httpd_version=2.4.54 ADD files/* /tmp/ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk update && adduser -SHs /sbin/nologin apache && apk add --no-cache -U gcc libc-dev make expat-dev pcre-dev openssl-dev libtool && cd /tmp/apr-${apr_version} && sed -i '/$RM "$cfgfile"/d' configure && ./configure --prefix=/usr/local/apr && make && make install && cd /tmp/apr-util-${apr_util_version} && ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install && cd /tmp/httpd-${httpd_version} && ./configure --prefix=/usr/local/apache --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork && make && make install && mv /tmp/entrypoint.sh / && apk del gcc make && rm -rf /tmp/* /var/cache/* EXPOSE 80 WORKDIR /usr/local/apache CMD ["/usr/local/apache/bin/httpd","-D","FOREGROUND"] ENTRYPOINT ["/bin/sh","/entrypoint.sh"] [root@localhost httpd]# podman build -t httpd:v4.0 . .... STEP 9/9: ENTRYPOINT ["/bin/sh","/entrypoint.sh"] COMMIT httpd:v6.0 --> eb89d86d65e Successfully tagged localhost/httpd:v6.0 eb89d86d65ef414d288a662331a44740015472d6539b25f95bc8abee8ce8addb [root@localhost httpd]# podman images //可以查看到鏡像已經比較小了 REPOSITORY TAG IMAGE ID CREATED SIZE localhost/httpd v6.0 eb89d86d65ef 8 seconds ago 120 MB docker.io/library/alpine latest 9c6f07244728 3 weeks ago 5.83 MB [root@localhost httpd]# cd [root@localhost ~]# mkdir -p /srv/web [root@localhost ~]# cd /srv/web/ [root@localhost web]# ls [root@localhost web]# echo "hello lnh" >index.html [root@localhost web]# cat index.html hello lnh [root@localhost web]# cd [root@localhost ~]# cd httpd/ [root@localhost httpd]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/httpd v6.0 eb89d86d65ef 8 seconds ago 120 MB docker.io/library/alpine latest 9c6f07244728 3 weeks ago 5.83 MB [root@localhost httpd]# podman run -d --name web -p 80:80 -v /srv/web/:/usr/local/apache/htdocs/:Z httpd:v6.0 //用制作的鏡像運行一個容器 a7d9d8c071e80360e3ad40ff7933337c8d9ecf24ef0fa81c72a2a85e7dec86af [root@localhost httpd]# podman ps //查看進程狀態 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a7d9d8c071e8 localhost/httpd:v6.0 /usr/local/apache... 4 seconds ago Up 4 seconds ago 0.0.0.0:80->80/tcp web [root@localhost httpd]# podman inspect -l |grep -i ipaddr //查看ip地址 "IPAddress": "10.88.0.10", "IPAddress": "10.88.0.10", [root@localhost httpd]# curl 10.88.0.10 //訪問成功 hello lnh
進行訪問:
上傳鏡像: [root@localhost httpd]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/httpd v6.0 eb89d86d65ef 9 minutes ago 120 MB docker.io/library/alpine latest 9c6f07244728 3 weeks ago 5.83 MB [root@localhost httpd]# podman tag httpd:v6.0 docker.io/lvnanhai66/httpd:v6.0 //做標簽使其和官方網站上面的一致(建議使用自己的用戶名) [root@localhost httpd]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/httpd v6.0 eb89d86d65ef 11 minutes ago 120 MB docker.io/lvnanhai66/httpd v6.0 eb89d86d65ef 11 minutes ago 120 MB docker.io/library/alpine latest 9c6f07244728 3 weeks ago 5.83 MB [root@localhost ~]# podman save docker.io/lvnanhai66/httpd:v6.0 -o myhttpd.tar //將其打包成為文件 Getting image source signatures Copying blob 994393dc58e7 done Copying blob ff52d230cd11 done Copying blob 7395d1756e8f done Copying config eb89d86d65 done Writing manifest to image destination Storing signatures [root@localhost ~]# ls anaconda-ks.cfg httpd myhttpd.tar [root@localhost ~]# scp myhttpd.tar 192.168.222.251:/root The authenticity of host '192.168.222.251 (192.168.222.251)' can't be established. ECDSA key fingerprint is SHA256:y11UDaNXs3AnvVUnZQfAim2VHAplF09YOvQp2NemHyk. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '192.168.222.251' (ECDSA) to the list of known hosts. root@192.168.222.251's password: myhttpd.tar 100% 114MB 92.2MB/s 00:01 //傳給安裝docker的虛擬主機上面
docker的安裝方法
在安裝了docker的虛擬主機上面進行上傳鏡像
[root@localhost ~]# ls anaconda-ks.cfg myhttpd.tar [root@localhost ~]# docker load -i myhttpd.tar //將鏡像導入 994393dc58e7: Loading layer 5.827MB/5.827MB ff52d230cd11: Loading layer 53.77MB/53.77MB 7395d1756e8f: Loading layer 60.25MB/60.25MB Loaded image: lvnanhai66/httpd:v6.0 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE lvnanhai66/httpd v6.0 eb89d86d65ef 26 minutes ago 115MB [root@localhost ~]# docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: lvnanhai66 Password: WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [root@localhost ~]# docker push lvnanhai66/httpd:v6.0 The push refers to repository [docker.io/lvnanhai66/httpd] 7395d1756e8f: Pushed ff52d230cd11: Pushed 994393dc58e7: Pushed v6.0: digest: sha256:b01a151e9b89e7cd994c1a6acb207183c9097bd140098bee0b63f0da35a05c02 size: 952
可以查看到上傳成功,并且只有31M左右,比較小
測試:
[root@localhost ~]# docker pull lvnanhai66/httpd:v6.0 //拉取自己制作的鏡像 v6.0: Pulling from lvnanhai66/httpd 213ec9aee27d: Pull complete c220467fa6e0: Pull complete f3a6cb94f126: Pull complete Digest: sha256:b01a151e9b89e7cd994c1a6acb207183c9097bd140098bee0b63f0da35a05c02 Status: Downloaded newer image for lvnanhai66/httpd:v6.0 docker.io/lvnanhai66/httpd:v6.0 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE lvnanhai66/httpd v6.0 eb89d86d65ef 54 minutes ago 115MB [root@localhost ~]# docker run -d lvnanhai66/httpd:v6.0 b7f7f743e574f1054afb559fada840361d4ca046e9698b8e4ccb9c2124949416 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b7f7f743e574 lvnanhai66/httpd:v6.0 "/bin/sh /entrypoint…" 5 seconds ago Up 4 seconds 80/tcp strange_hofstadter //利用自己制作鏡像成功運行一個容器
-
指令
+關注
關注
1文章
607瀏覽量
35711 -
鏡像
+關注
關注
0文章
164瀏覽量
10724 -
devops
+關注
關注
0文章
114瀏覽量
12025
原文標題:提升 DevOps 效率!從基礎到進階的 Dockerfile 編寫技巧
文章出處:【微信號:magedu-Linux,微信公眾號:馬哥Linux運維】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
評論