制作 Docker 镜像

news2024/11/24 9:02:18

目录

1 docker镜像介绍

1.1 docker的镜像结构  

1.2 镜像运行的基本原理

1.3 镜像获得方式

2 构建 docker 镜像 Dockerfile

2.1 Dockerfile 基础参数介绍

2.2 实现参数功能示例

2.2.1 FROM LABEL COPY

2.2.2 ADD

2.2.3 ENV 和 CMD与ENTRYPOINT

2.2.3.1 CMD的替代性

2.2.3.2 ENTRYPOINT的不可替代性

2.2.4 EXPOSE:端口暴露

2.2.5 VOLUME:指定容器的目录将他挂载到宿主机上

2.3 使用Dockerfile构建nginx镜像

2.3.1 系统更换网络源

2.3.2 编写Dockerfile镜像文件

2.3.3 镜像优化示例


1 docker镜像介绍

1.1 docker的镜像结构  

  • 共享宿主机的kernel
  • base镜像提供的是最小的Linux发行版
  • 同一docker主机支持运行多种Linux发行版
  • 采用分层结构的最大好处是:共享资源

1.2 镜像运行的基本原理

  • Copy-on-Write 可写容器层
  • 容器层以下所有镜像层都是只读的
  • docker从上往下依次查找文件
  • 容器层保存镜像变化的部分,并不会对镜像本身进行任何修改
  • 一个镜像最多127

1.3 镜像获得方式

  • 基本镜像通常由软件官方提供
  • 企业镜像可以用官方镜像+Dockerfile来生成
  • 系统关于镜像的获取动作有两种:
docker pull 镜像地址
docker load -i 本地镜像包

2 构建 docker 镜像 Dockerfile

2.1 Dockerfile 基础参数介绍

指令描述
FROM指定基础镜像,例如:FROM busybox:version
COPY复制文件,例如:COPY file /file 或者 COPY ["file","/"]
MAINTAINER指定作者信息,例如邮箱:MAINTAINER user@example.com在最新版的Docker中用LABEL KEY="VALUE"代替
ADD

功能和COPY相似,指定压缩文件或url,

例如:ADD test.tar /mnt 或者 ADD http://ip/test.tar /mnt

ENV指定环境变量,例如:ENV FILENAME test
EXPOSE暴露容器端口,例如:EXPOSE 80
VOLUME声明数据卷,通常指数据挂载点,例如:VOLUME ["/var/www/html"]
WORKDIR切换路径,例如:WORKDIR /mnt
RUN在容器中运行的指令,例如:touch file
CMD

在启动容器时自动运行的动作,可以被覆盖,

例如:CMD echo FILENAME会调用shell解析

例如:CMD["/bin/sh","−c","echoFILENAME"] 不调用shell解析

ENTRYPOINT和CMD功能和用法类似,但动作不可被覆盖

2.2 实现参数功能示例

2.2.1 FROM LABEL COPY

[root@rockynode-1 dockerfile]# vim Dockerfile 
FROM busybox:latest
LABEL mail = shuyan@123
COPY shuyan /


[root@rockynode-1 dockerfile]# docker build -t shuyan_copy:v1 .
[+] Building 0.1s (7/7) FINISHED         docker:default
 => [internal] load build definition from Dockerf  0.0s
 => => transferring dockerfile: 155B               0.0s
 => WARN: LegacyKeyValueFormat: "LABEL key=value"  0.0s
 => [internal] load metadata for docker.io/librar  0.0s
 => [internal] load .dockerignore                  0.0s
 => => transferring context: 2B                    0.0s
 => [internal] load build context                  0.0s
 => => transferring context: 87B                   0.0s
 => [1/2] FROM docker.io/library/busybox:latest    0.0s
 => [2/2] COPY shuyan /                            0.0s
 => exporting to image                             0.0s
 => => exporting layers                            0.0s
 => => writing image sha256:9185f618183ab1a307bfb  0.0s
 => => naming to docker.io/library/shuyan_copy:v1  0.0s

 1 warning found (use docker --debug to expand):
 - LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy "LABEL key value" format (line 2)

使用 ctrl+pq 不删除 镜像退出

[root@rockynode-1 dockerfile]# docker history shuyan_copy:v1 
IMAGE          CREATED         CREATED BY                          SIZE      COMMENT
9185f618183a   5 minutes ago   COPY shuyan / # buildkit            0B        buildkit.dockerfile.v0
<missing>      5 minutes ago   LABEL mail== shuyan@123             0B        buildkit.dockerfile.v0
<missing>      15 months ago   BusyBox 1.36.1 (glibc), Debian 12   4.26MB  


[root@rockynode-1 dockerfile]# docker ps -a
CONTAINER ID   IMAGE            COMMAND   CREATED         STATUS         PORTS     NAMES
c7d1405cc637   shuyan_copy:v1   "sh"      2 minutes ago   Up 2 minutes             test
[root@rockynode-1 dockerfile]# docker rm -f test 
test

2.2.2 ADD

[root@rockynode-1 dockerfile]# touch shuyanfile{1..3}
[root@rockynode-1 dockerfile]# tar zcf shuyanflie.tar.gz shuyanfile*
[root@rockynode-1 dockerfile]# 
FROM busybox:latest
LABEL mail = shuyan@123
COPY shuyan /
ADD shuyanflie.tar.gz /


[root@rockynode-1 dockerfile]# docker build -t shuyan_add:v1 .
[+] Building 0.1s (8/8) FINISHED                                           docker:default
 => [internal] load build definition from Dockerfile                                 0.0s
 => => transferring dockerfile: 179B                                                 0.0s
 => WARN: LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy   0.0s
 => [internal] load metadata for docker.io/library/busybox:latest                    0.0s
 => [internal] load .dockerignore                                                    0.0s
 => => transferring context: 2B                                                      0.0s
 => [1/3] FROM docker.io/library/busybox:latest                                      0.0s
 => [internal] load build context                                                    0.0s
 => => transferring context: 332B                                                    0.0s
 => CACHED [2/3] COPY shuyan /                                                       0.0s
 => [3/3] ADD shuyanflie.tar.gz /                                                    0.0s
 => exporting to image                                                               0.0s
 => => exporting layers                                                              0.0s
 => => writing image sha256:3c20eac277664d5e3d2c02efbfda238748c1cd52dfb89ab26141431  0.0s
 => => naming to docker.io/library/shuyan_add:v1                                     0.0s

 1 warning found (use docker --debug to expand):
 - LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy "LABEL key value" format (line 2)
[root@rockynode-1 dockerfile]# docker images 
REPOSITORY           TAG           IMAGE ID       CREATED          SIZE
shuyan_add           v1            3c20eac27766   23 seconds ago   4.26MB
nginx                1.26-alpine   9703b2608a98   12 days ago      43.3MB
nginx                latest        5ef79149e0ec   12 days ago      188MB
busybox              latest        65ad0d468eb1   15 months ago    4.26MB
timinglee/game2048   latest        19299002fdbe   7 years ago      55.5MB
timinglee/mario      latest        9a35a9e43e8c   8 years ago      198MB
[root@rockynode-1 dockerfile]# docker run -it --name test shuyan_add:v1 
/ # ls
bin          home         proc         shuyanfile1  sys          var
dev          lib          root         shuyanfile2  tmp
etc          lib64        shuyan       shuyanfile3  usr


[root@rockynode-1 dockerfile]# docker rm -f test 
test

2.2.3 ENV 和 CMD与ENTRYPOINT

FROM busybox:latest
LABEL mail = shuyan@123
COPY shuyan /
ADD shuyanflie.tar.gz /
ENV NAME shuyan   # 设置变量
CMD echo $NAME    # 打印变量

[root@rockynode-1 dockerfile]# docker build -t shuyan_env_cmd .
[+] Building 0.1s (8/8) FINISHED                                           docker:default
 => [internal] load build definition from Dockerfile                                 0.0s
 => => transferring dockerfile: 210B                                                 0.0s
 => WARN: LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy   0.0s
 => WARN: LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "E  0.0s
 => WARN: JSONArgsRecommended: JSON arguments recommended for CMD to prevent uninte  0.0s
 => [internal] load metadata for docker.io/library/busybox:latest                    0.0s
 => [internal] load .dockerignore                                                    0.0s
 => => transferring context: 2B                                                      0.0s
 => [1/3] FROM docker.io/library/busybox:latest                                      0.0s
 => [internal] load build context                                                    0.0s
 => => transferring context: 182B                                                    0.0s
 => CACHED [2/3] COPY shuyan /                                                       0.0s
 => CACHED [3/3] ADD shuyanflie.tar.gz /                                             0.0s
 => exporting to image                                                               0.0s
 => => exporting layers                                                              0.0s
 => => writing image sha256:74952b428aa082102f25e0d25f84016907e7cb6845187dc671b7088  0.0s
 => => naming to docker.io/library/shuyan_env_cmd                                    0.0s

 3 warnings found (use docker --debug to expand):
 - LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy "LABEL key value" format (line 2)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 5)
 - JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals (line 6)
[root@rockynode-1 dockerfile]# docker images 
REPOSITORY           TAG           IMAGE ID       CREATED         SIZE
shuyan_env_cmd       latest        74952b428aa0   6 minutes ago   4.26MB
nginx                1.26-alpine   9703b2608a98   12 days ago     43.3MB
nginx                latest        5ef79149e0ec   12 days ago     188MB
busybox              latest        65ad0d468eb1   15 months ago   4.26MB
timinglee/game2048   latest        19299002fdbe   7 years ago     55.5MB
timinglee/mario      latest        9a35a9e43e8c   8 years ago     198MB

dockerfile]# docker run -it --rm --name test shuyan_env_cmd:latest 
shuyan   # 直接输出


[root@rockynode-1 dockerfile]# docker rmi shuyan_env_cmd:latest 
2.2.3.1 CMD的替代性
[root@rockynode-1 dockerfile]# docker build -t shuyan_cmd .
[+] Building 0.1s (8/8) FINISHED                                           docker:default
 => [internal] load build definition from Dockerfile                                 0.0s
 => => transferring dockerfile: 252B                                                 0.0s
 => WARN: LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy   0.0s
 => WARN: LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "E  0.0s
 => [internal] load metadata for docker.io/library/busybox:latest                    0.0s
 => [internal] load .dockerignore                                                    0.0s
 => => transferring context: 2B                                                      0.0s
 => [1/3] FROM docker.io/library/busybox:latest                                      0.0s
 => [internal] load build context                                                    0.0s
 => => transferring context: 182B                                                    0.0s
 => CACHED [2/3] COPY shuyan /                                                       0.0s
 => CACHED [3/3] ADD shuyanflie.tar.gz /                                             0.0s
 => exporting to image                                                               0.0s
 => => exporting layers                                                              0.0s
 => => writing image sha256:6c75da7d6a03a1e2b0d6caab10eb5e0d97186a17c2091ab3ed28618  0.0s
 => => naming to docker.io/library/shuyan_cmd                                        0.0s

 2 warnings found (use docker --debug to expand):
 - LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy "LABEL key value" format (line 2)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 5)
dockerfile]# docker run -it --name test --rm shuyan_cmd:latest 
shuyan
[root@rockynode-1 dockerfile]# docker images 
REPOSITORY           TAG           IMAGE ID       CREATED          SIZE
shuyan_cmd           latest        6c75da7d6a03   24 minutes ago   4.26MB
nginx                1.26-alpine   9703b2608a98   12 days ago      43.3MB
nginx                latest        5ef79149e0ec   12 days ago      188MB
busybox              latest        65ad0d468eb1   15 months ago    4.26MB
timinglee/game2048   latest        19299002fdbe   7 years ago      55.5MB
timinglee/mario      latest        9a35a9e43e8c   8 years ago      198MB

[root@rockynode-1 dockerfile]# docker rmi shuyan_cmd:latest 
Untagged: shuyan_cmd:latest
Deleted: sha256:6c75da7d6a03a1e2b0d6caab10eb5e0d97186a17c2091ab3ed2861888d1a5979
[root@rockynode-1 dockerfile]# docker images 
REPOSITORY           TAG           IMAGE ID       CREATED         SIZE
nginx                1.26-alpine   9703b2608a98   12 days ago     43.3MB
nginx                latest        5ef79149e0ec   12 days ago     188MB
busybox              latest        65ad0d468eb1   15 months ago   4.26MB
timinglee/game2048   latest        19299002fdbe   7 years ago     55.5MB
timinglee/mario      latest        9a35a9e43e8c   8 years ago     198MB
[root@rockynode-1 dockerfile]# docker build -t shuyan_cmd:v1 .
[+] Building 0.1s (8/8) FINISHED                                           docker:default
 => [internal] load build definition from Dockerfile                                 0.0s
 => => transferring dockerfile: 252B                                                 0.0s
 => WARN: LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy   0.0s
 => WARN: LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "E  0.0s
 => [internal] load metadata for docker.io/library/busybox:latest                    0.0s
 => [internal] load .dockerignore                                                    0.0s
 => => transferring context: 2B                                                      0.0s
 => [1/3] FROM docker.io/library/busybox:latest                                      0.0s
 => [internal] load build context                                                    0.0s
 => => transferring context: 182B                                                    0.0s
 => CACHED [2/3] COPY shuyan /                                                       0.0s
 => CACHED [3/3] ADD shuyanflie.tar.gz /                                             0.0s
 => exporting to image                                                               0.0s
 => => exporting layers                                                              0.0s
 => => writing image sha256:6c75da7d6a03a1e2b0d6caab10eb5e0d97186a17c2091ab3ed28618  0.0s
 => => naming to docker.io/library/shuyan_cmd:v1                                     0.0s

 2 warnings found (use docker --debug to expand):
 - LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy "LABEL key value" format (line 2)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 5)

发现使用cmd 的会被 shell 替代 

dockerfile]# docker run -it --name test --rm shuyan_cmd:v1 sh
/ # exit

[root@rockynode-1 dockerfile]# docker rmi shuyan_cmd:v1 
Untagged: shuyan_cmd:v1
Deleted: sha256:6c75da7d6a03a1e2b0d6caab10eb5e0d97186a17c2091ab3ed2861888d1a5979
2.2.3.2 ENTRYPOINT的不可替代性
[root@rockynode-1 dockerfile]# vim Dockerfile
FROM busybox:latest
LABEL mail = shuyan@123
COPY shuyan /
ADD shuyanflie.tar.gz /
ENV NAME shuyan
#CMD echo $NAME
#CMD ["/bin/sh","-c","/bin/echo $NAME"]
ENTRYPOINT ["/bin/sh","-c","/bin/echo $NAME"]  # 不可被替代


[root@rockynode-1 dockerfile]# docker build -t shuyan_ent:v1 .
[+] Building 0.1s (8/8) FINISHED                                           docker:default
 => [internal] load build definition from Dockerfile                                 0.0s
 => => transferring dockerfile: 299B                                                 0.0s
 => WARN: LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy   0.0s
 => WARN: LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "E  0.0s
 => [internal] load metadata for docker.io/library/busybox:latest                    0.0s
 => [internal] load .dockerignore                                                    0.0s
 => => transferring context: 2B                                                      0.0s
 => [1/3] FROM docker.io/library/busybox:latest                                      0.0s
 => [internal] load build context                                                    0.0s
 => => transferring context: 182B                                                    0.0s
 => CACHED [2/3] COPY shuyan /                                                       0.0s
 => CACHED [3/3] ADD shuyanflie.tar.gz /                                             0.0s
 => exporting to image                                                               0.0s
 => => exporting layers                                                              0.0s
 => => writing image sha256:c93e8d613c2ec68595594ce0455e67bdbd12b83190ca31c598bcdb2  0.0s
 => => naming to docker.io/library/shuyan_ent:v1                                     0.0s

 2 warnings found (use docker --debug to expand):
 - LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy "LABEL key value" format (line 2)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 5)

[root@rockynode-1 dockerfile]# docker images 
REPOSITORY           TAG           IMAGE ID       CREATED          SIZE
shuyan_ent           v1            c93e8d613c2e   29 minutes ago   4.26MB
nginx                1.26-alpine   9703b2608a98   12 days ago      43.3MB
nginx                latest        5ef79149e0ec   12 days ago      188MB
busybox              latest        65ad0d468eb1   15 months ago    4.26MB
timinglee/game2048   latest        19299002fdbe   7 years ago      55.5MB
timinglee/mario      latest        9a35a9e43e8c   8 years ago      198MB

dockerfile]# docker run --name test --rm -it shuyan_ent:v1 
shuyan
dockerfile]# docker run --name test --rm -it shuyan_ent:v1 sh
shuyan

2.2.4 EXPOSE:端口暴露

[root@rockynode-1 _data]# vim /root/dockerfile/Dockerfile 
FROM busybox
MAINTAINER shuyan@com
EXPOSE 80 443  # 暴露80与443端口
[root@rockynode-1 dockerfile]# docker ps 
CONTAINER ID   IMAGE        COMMAND   CREATED         STATUS         PORTS             NAMES
2c53843b7bb4   busybox:v3   "sh"      4 minutes ago   Up 4 minutes   80/tcp, 443/tcp   test

2.2.5 VOLUME:指定容器的目录将他挂载到宿主机上

[root@rockynode-1 _data]# vim /root/dockerfile/Dockerfile 

FROM busybox
MAINTAINER shuyan@com
EXPOSE 80 443
VOLUME /var/www/html   # 将容器这个目录内的东西挂载到宿主机
WORKDIR /var/www/html # 进入容器内马上切换到的目录
[root@rockynode-1 dockerfile]# docker run -it --name=test busybox:v2
/var/www/html # ls
/var/www/html # touch 1 2 3 4 5  6 7
/var/www/html # ls
1  2  3  4  5  6  7
/var/www/html # [root@rockynode-1 dockerfile]# 
[root@rockynode-1 dockerfile]# docker inspect test | grep Moun -A 6

--
        "Mounts": [
            {
                "Type": "volume",
                "Name": "d52249eddca8aaf9027c73b8b9051ca68f49c782b44b16b71598ba27f73a3706",
                "Source": "/var/lib/docker/volumes/d52249eddca8aaf9027c73b8b9051ca68f49c782b44b16b71598ba27f73a3706/_data",
                "Destination": "/var/www/html",
                "Driver": "local",
[root@rockynode-1 dockerfile]# ls /var/lib/docker/volumes/d52249eddca8aaf9027c73b8b9051ca68f49c782b44b16b71598ba27f73a3706/_data
1  2  3  4  5  6  7

2.3 使用Dockerfile构建nginx镜像

使用centos镜像制作NGINX镜像

2.3.1 系统更换网络源

由于在centos7的国内镜像已经过期,所以需要自己搭一个服务器,将另一台有光盘镜像  的centos将镜像挂载到上边

[root@rockynode-1 dockerfile]# yum install httpd

Listen 8080

[root@rockynode-1 dockerfile]# mkdir /var/www/html/centos7
[root@rockynode-1 dockerfile]# mount /dev/sr1 /var/www/html/centos7/
[root@rockynode-1 dockerfile]# systemctl restart httpd

2.3.2 编写Dockerfile镜像文件

需要准备NGINX源码包

[root@rockynode-1 dockerfile]# docker load -i centos-7.tar.gz 
[root@rockynode-1 dockerfile]# docker images 
REPOSITORY           TAG           IMAGE ID       CREATED          SIZE
nginx                1.26-alpine   9703b2608a98   12 days ago      43.3MB
nginx                latest        5ef79149e0ec   12 days ago      188MB
busybox              latest        65ad0d468eb1   15 months ago    4.26MB
centos               7             eeb6ee3f44bd   2 years ago      204MB
timinglee/game2048   latest        19299002fdbe   7 years ago      55.5MB
timinglee/mario      latest        9a35a9e43e8c   8 years ago      198MB

首先需要运行一个容器将他的yum源改成刚才配置的http服务器网址

[root@rockynode-1 dockerfile]# docker run -it --name=centos7 centos:7
[root@65ed46926df1 /]# [root@rockynode-1 dockerfile]# 
[root@rockynode-1 dockerfile]# docker exec -it centos7 sh
sh-4.2# cd /etc/yum.repos.d/
sh-4.2# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
CentOS-CR.repo    CentOS-Media.repo      CentOS-Vault.repo    CentOS-x86_64-kernel.repo
sh-4.2# rm -fr *
sh-4.2# vi centos.repo
[rhel]
name=rhel
baseurl=http://172.17.0.1:8080/centos7
gpgcheck=0

# ctrl + pq 退出
sh-4.2# read escape sequence  

# 将修改好的容器提交为镜像
dockerfile]# docker commit -m "cent2_repo" centos7 centos7:repo

可查看到容器的IP,他是与宿主机进行桥接的,也就是说链接这个就等于链接宿主机 

编写Dockerfile 文件

[root@rockynode-1 dockerfile]# vim Dockerfile 
FROM centos7:repo
LABEL mail = shuyan@123
ADD nginx-1.26.1.tar.gz /mnt
WORKDIR /mnt/nginx-1.26.1
RUN yum install gcc make pcre-devel openssl-devel -y && \
./configure --prefix=/usr/local/nginx --with-http_ssl_module \
--with-http_stub_status_module && make && make install && \
yum clean all && rm -rf /mnt/nginx-1.26.1
EXPOSE 80 443
VOLUME ["/usr/local/nginx/html"]
CMD ["/usr/local/nginx/sbin/nginx","-g","daemon off"]

[root@rockynode-1 dockerfile]# docker build -t centos:v3 .
[+] Building 36.7s (9/9) FINISHED                                                                                               docker:default
 => [internal] load build definition from Dockerfile                                                                                      0.0s
 => => transferring dockerfile: 520B                                                                                                      0.0s
 => WARN: LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy "LABEL key value" format (line 2)                      0.0s
 => [internal] load metadata for docker.io/library/centos7:repo                                                                           0.0s
 => [internal] load .dockerignore                                                                                                         0.0s
 => => transferring context: 2B                                                                                                           0.0s
 => [internal] load build context                                                                                                         0.0s
 => => transferring context: 102B                                                                                                         0.0s
 => [1/4] FROM docker.io/library/centos7:repo                                                                                             0.0s
 => [2/4] ADD nginx-1.26.1.tar.gz /mnt                                                                                                    0.3s
 => [3/4] WORKDIR /mnt/nginx-1.26.1                                                                                                       0.0s
 => [4/4] RUN yum install gcc make pcre-devel openssl-devel -y && ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-h  36.0s
 => exporting to image                                                                                                                    0.3s 
 => => exporting layers                                                                                                                   0.3s 
 => => writing image sha256:68cf4567b2da65477bf5bfcb64ec9e8878a8d13fa8a3a593eb51a2ff7e1ec886                                              0.0s 
 => => naming to docker.io/library/centos:v3                                                                                              0.0s 
                                                                                                                                               
 1 warning found (use docker --debug to expand):                                                                                               
 - LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy "LABEL key value" format (line 2)
[root@rockynode-1 dockerfile]# docker images 
REPOSITORY           TAG           IMAGE ID       CREATED              SIZE
centos               v3            68cf4567b2da   8 seconds ago        292MB
centos7              repo          9d9f5c6e1915   About a minute ago   204MB
centos               repo          5726ef394719   2 hours ago          228MB
nginx                1.26-alpine   9703b2608a98   12 days ago          43.3MB
nginx                latest        5ef79149e0ec   12 days ago          188MB
busybox              latest        65ad0d468eb1   15 months ago        4.26MB
centos               7             eeb6ee3f44bd   2 years ago          204MB
timinglee/game2048   latest        19299002fdbe   7 years ago          55.5MB
timinglee/mario      latest        9a35a9e43e8c   8 years ago          198MB

2.3.3 镜像优化示例

# 编译安装安装
FROM centos:repo AS build
LABEL mail = shuyan@123
ADD nginx-1.26.1.tar.gz /mnt
WORKDIR /mnt/nginx-1.26.1
RUN yum install gcc make pcre-devel openssl-devel -y && \
./configure --prefix=/usr/local/nginx --with-http_ssl_module \
--with-http_stub_status_module && make && make install && \
yum clean all && rm -rf /mnt/nginx-1.26.1

# 软件迁移
FROM centos:repo
COPY --from=build /usr/local/nginx /usr/local/nginx
EXPOSE 80 443
VOLUME ["/usr/local/nginx/html"]
CMD ["/usr/local/nginx/sbin/nginx","-g","daemon off;"]

为了验证这一说法可以制作提交两个镜像

dockerfile]# docker commit -m "ngin_2" nginx_centos centos2:repo
dockerfile]# docker commit -m "ngin_2" nginx_centos centos3:repo
dockerfile]# docker images

[root@rockynode-1 dockerfile]# docker build -t centos:v4 .
[+] Building 0.1s (12/12) FINISHED                                                                                              docker:default
 => [internal] load build definition from Dockerfile                                                                                      0.0s
 => => transferring dockerfile: 601B                                                                                                      0.0s
 => WARN: LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy "LABEL key value" format (line 2)                      0.0s
 => [internal] load metadata for docker.io/library/centos2:repo                                                                           0.0s
 => [internal] load metadata for docker.io/library/centos3:repo                                                                           0.0s
 => [internal] load .dockerignore                                                                                                         0.0s
 => => transferring context: 2B                                                                                                           0.0s
 => [internal] load build context                                                                                                         0.0s
 => => transferring context: 102B                                                                                                         0.0s
 => [stage-1 1/2] FROM docker.io/library/centos3:repo                                                                                     0.0s
 => [build 1/4] FROM docker.io/library/centos2:repo                                                                                       0.0s
 => CACHED [build 2/4] ADD nginx-1.26.1.tar.gz /mnt                                                                                       0.0s
 => CACHED [build 3/4] WORKDIR /mnt/nginx-1.26.1                                                                                          0.0s
 => CACHED [build 4/4] RUN yum install gcc make pcre-devel openssl-devel -y && ./configure --prefix=/usr/local/nginx --with-http_ssl_mod  0.0s
 => CACHED [stage-1 2/2] COPY --from=build /usr/local/nginx /usr/local/nginx                                                              0.0s
 => exporting to image                                                                                                                    0.0s
 => => exporting layers                                                                                                                   0.0s
 => => writing image sha256:7f2c20fc731e9511b999d5786b03f4d697d9ce6204844dc32f111dbc63cde423                                              0.0s
 => => naming to docker.io/library/centos:v4                                                                                              0.0s

 1 warning found (use docker --debug to expand):
 - LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy "LABEL key value" format (line 2)

启动容器查看尝试是否能连接

dockerfile]# docker run -it -d -p 80:80 --name=nginx_new centos:v4
6783951e1fae546aafbd0c76f2c00c189e78b02c4bf01937177c57465153cc1c

dockerfile]# docker ps 
CONTAINER ID   IMAGE       COMMAND                   CREATED         STATUS         PORTS                                        NAMES
6783951e1fae   centos:v4   "/usr/local/nginx/sb…"   5 seconds ago   Up 4 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp   nginx_new

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2091455.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

使用3D数字人做视频

用3D数字人做视频 漂亮精致 3D数字人定制4 动作流畅、音乐上的表现 thatgirl 支持私人定制模型 你愿意捐献所有的财产吗 想搭建这样的数字人的请和我们联系 使用3D数字人做视频https://www.jinshuangshi.com/forum.php?modviewthread&tid248 (出处: 金双石科技)

利用session.upload_progress执行文件包含

1.session.upload_progress的作用&#xff1a; session.upload_progress最初是PHP为上传进度条设计的一个功能&#xff0c;在上传文件较大的情况下&#xff0c;PHP将进行流式上传&#xff0c;并将进度信息放在Session中&#xff08;包含用户可控的值&#xff09;&#xff0c;即…

Ethercat设备数据 转IEC61850项目案例

目录 1 案例说明 1 2 VFBOX网关工作原理 1 3 准备工作 2 5 设置网关采集ETHERCAT数据 5 6 用IEC61850协议转发数据 7 7 网关使用多个逻辑设备和逻辑节点的方法 9 8 安装NPCAP 10 9 案例总结 11 1 案例说明 设置网关采集EtherCAT设备数据把采集的数据转成IEC61850协议转发给其…

08:Logic软件原理图添加元件

1.导入外部库文件 2.添加元件

Veeam Data Platform 12.2 发布下载,新增功能概览

Veeam Data Platform 12.2 发布下载&#xff0c;新增功能概览 面向混合云和多云的 云端、虚拟和物理环境 备份和恢复 监控和分析 恢复编排 请访问原文链接&#xff1a;https://sysin.org/blog/veeam-data-platform/&#xff0c;查看最新版。原创作品&#xff0c;转载请保留出…

飞致云开源社区月度动态报告(2024年8月)

自2023年6月起&#xff0c;中国领先的开源软件公司FIT2CLOUD飞致云以月度为单位发布《飞致云开源社区月度动态报告》&#xff0c;旨在向广大社区用户同步飞致云旗下系列开源软件的发展情况&#xff0c;以及当月主要的产品新版本发布、社区运营成果等相关信息。 飞致云开源大屏…

计算机组成原理:实验三数据通路组成实验

一、实验目的 1.将双端口通用寄存器堆和双端口存储器模块联机&#xff1b; 2.进一步熟悉计算机的数据通路&#xff1b; 3.掌握数字逻辑电路中故障的一般规律&#xff0c;以及排除故障的一般原则和方法&#xff1b; 4.锻炼分析问题与解决问题的能力&#xff0c;在出现故障的…

Windows 10远程桌面连接设置

0 Preface/Foreword 0.1 Remote desktop &#xff08;远程桌面&#xff09; Remote Desktop lets you connect to or control this PC from a remote device by using a Remote Desktop client (available for Windows, Android, iOS and macOS). Youll be able to work fro…

15年让爱轮回

15年前&#xff0c;运巧的命运齿轮因一位记者的稿件悄然转动&#xff0c;运巧这个名字&#xff0c;真的是命运的巧合&#xff0c;把她和邦尔骨科连接在了一起&#xff0c;她的人生轨迹因一家医院的善举发生了改变。那时的她&#xff0c;面临生活的重重困境&#xff0c;求学之路…

通义 AI 再次颠覆创作体验:一句话即可生成PPT

&#x1f195;通义 AI 再次颠覆创作体验&#xff1a;一句话即可生成PPT &#x1f389; 最近&#xff0c;科技圈再度被通义 AI 的最新功能刷屏&#xff01;8月30日&#xff0c;通义网页版正式上线了让无数办公族翘首以盼的“PPT 创作”功能。这一革新功能不仅为内容创作者带来了…

制作人偶动画Character Animator

每个人都可以通过表演开始制作动画。无需具备专业的操控知识。 入门模式提供示例人偶&#xff0c;可帮助您快速创建动画。选择人偶或导入人偶&#xff0c;然后添加或录制语音。 每个示例人偶都有一个完备的“控件”面板&#xff0c;其中包含多种姿势和情绪。 您可以通过选择“自…

【TDesign】如何修改CSS变量

Tdesign的组件想通过style定义样式没效果, 可以通过组件api文档修改, 组件提供了下列 CSS 变量&#xff0c;可用于自定义样式。 比如Cell, https://tdesign.tencent.com/miniprogram/components/cell?tabapi 提供了&#xff1a; –td-cell-left-icon-color 图标颜色 –td-cell…

【每日一题】【想通后的诈骗题】Wakey Wakey 牛客挑战赛76 A题 C++

牛客挑战赛76 A题 Wakey Wakey 题目背景 牛客挑战赛76 题目描述 样例 #1 样例输入 #1 2 2 3 2 10000 100000 2333样例输出 #1 1 2014备注 1 ≤ T ≤ 10 1\le T\le 10 1≤T≤10 1 ≤ n , m ≤ 1 0 5 1\le n,m \le 10^5 1≤n,m≤105 1 ≤ p ≤ 1 0 9 1\le p \le 10^9 1…

干货分享|分享一款自己常用的桌面整理神器 WPS桌面整理

问题&#xff1a;下面两张图是使用WPS桌面整理前后的对比。 使用方法&#xff1a; 1.打开WPS 2.点击桌面右下角WPS办公助手--选择桌面整理--整理桌面 注&#xff1a;桌面整理后&#xff0c;可以通过右键点击格子并根据个人喜好进行编辑。操作简便&#xff0c;大家自行尝试和探索…

线性代数|机器学习-P31完成一个秩为1的矩阵

文章目录 1. 大纲2. 填充秩1矩阵2.1 举例2.2 二分图 3. 循环卷积矩阵 1. 大纲 给定一个秩为1的矩阵A&#xff0c;m行&#xff0c;n列&#xff0c;如果在矩阵A中给定mn-1 个非零的值&#xff0c;请问如何填充这个矩阵A,使得矩阵A 填满&#xff1f;卷积和循环卷积矩阵&#xff0…

通过Amazon Bedrock上的Stability AI模型开发生成式AI应用(上篇)

快来用人工智能生成图像开发生成式AI图像应用&#xff01;今天小李哥就来介绍亚马逊云科技推出的国际前沿人工智能模型平台Amazon Bedrock上的Stability Diffusion模型。接下来我将带大家沉浸式实操Stability Difussion模型&#xff0c;带大家手把手体验该模型的每个特色功能&a…

MySQL-进阶篇-SQL优化(插入数据优化、主键优化、order by优化、group by优化、limit优化、count优化、update优化)

文章目录 1. 插入数据优化1.1 使用批量插入1.2 批量插入数据时手动提交事务1.3 按主键的顺序插入1.4 大批量插入数据时使用 load 指令 2. 主键优化2.1 数据组织方式2.2 页分裂2.3 页合并2.4 主键的设计原则2.4.1 降低主键的长度2.4.2 使用 AUTO_INCREMENT 自增主键2.4.3 尽量不…

Javascript归纳与总结——this指向及其改变、new关键字与原型链、异步、闭包和函数防抖与节流

this指向及其改变 普通函数在调用时&#xff0c;this为obj.obj1.fun(),this->obj1,箭头函数在声明定义时this->obj。 Javascript中bind、call、apply區別-CSDN博客 new关键字与原型链 从原型链视角解读VueComponent与Vue关系_vue中重要的原型链关系-CSDN博客 prototy…

开放式耳机是不是智商税?年度开放式耳机推荐2024产品揭秘

现在越来越多的人开始注重耳道健康&#xff0c;开放式耳机也越来越受大家的欢迎&#xff0c;因为这种开放式的设计是不进入耳道&#xff0c;这样能够保护我们的耳道健康&#xff0c;大大减少细菌的滋生。 但是就会有小伙伴说了&#xff0c;那开放式耳机是不是智商税呢&#xff…