简体   繁体   English

Docker映像构建(摆脱依赖关系)

[英]Docker Image Build (Get rid of Dependencies)

I am building a php docker image from the base image of php:7.2-fpm-alpine , where some custom php extension is needed. 我正在从php:7.2-fpm-alpine的基本映像构建一个php docker映像,其中需要一些自定义php扩展名。

Like the following commands for installing dependencies and some extra extension. 类似于以下用于安装依赖项和一些额外扩展的命令。

RUN apk upgrade --update && apk add libpng-dev libjpeg-turbo-dev \
 freetype-dev libbz2 libxml2-dev libxml2 bzip2-dev libxslt libxslt-dev \
 && docker-php-ext-install bcmath calendar gd hash zip pdo_mysql

Since I need to manually install dependencies for my extensions, compiled it to get something like bcmath.so gd.so . 由于我需要为扩展程序手动安装依赖项,因此将其编译为类似bcmath.so gd.so

I am thinking if I can get rid off those dependencies and just copy the *.so into the new image, Since I am planting to use a multi-stage build in Dockerfile. 我在想是否可以摆脱这些依赖关系,而只是将*.so复制到新映像中,因为我打算在Dockerfile中使用多阶段构建。

The question is can I get rid of the GCC+ compiler and some other dependencies(openssl, curl)? 问题是我可以摆脱GCC +编译器和其他一些依赖项(openssl,curl)吗? and just grape the compiled result to the new image? 只是将编译结果转换成新图像?

Create a directory on host operating system. 在主机操作系统上创建目录。 Use Docker Volume to mount your directory to Container, to the place where your *.so are supposed to be found. 使用Docker Volume将目录挂载到Container上应找到* .so的位置。

Once you've compiled the extensions, you should be able to get rid of the -dev packages at least. 编译了扩展之后,至少应该可以摆脱-dev软件包。 The -dev packages include things like the c source header files (.h). -dev软件包包括c源头文件(.h)之类的东西。

So in your example, you install libxml2-dev and libxml2. 因此,在您的示例中,您将安装libxml2-dev和libxml2。 In this case, the libxml2 package is the files needed to run the code, libxml2-dev is the package needed to compile any code that uses libxml2. 在这种情况下,libxml2软件包是运行代码所需的文件,libxml2-dev是编译使用libxml2的任何代码所需的软件包。 When you compile the extension for PHP, the extension doesn't include all of the binaries to run the particular feature, it usually relies on the packages installed on the OS. 当您编译PHP扩展时,该扩展并不包括所有运行特定功能的二进制文件,它通常依赖于OS上安装的软件包。

You could get rid of gcc, and some of the support stuff, but you may need to go through a process of removing a package and then testing if anything breaks. 您可以摆脱gcc和一些支持的内容,但是您可能需要经历一个删除软件包的过程,然后测试是否有任何问题。

It may also be possible to remove some of the modules within PHP, again this depends on your code and what that does. 也有可能删除PHP中的某些模块,这又取决于您的代码及其作用。 Although this is beyond what I've done and I'm not sure of the benefits of doing this. 尽管这超出了我的工作范围,但我不确定这样做的好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用已弃用的依赖关系构建Docker映像 - Building a Docker image with deprecated dependencies 让 composer(php 依赖管理器)在 docker 镜像构建上运行 - Get composer (php dependency manager) to run on a docker image build 无法在Docker映像中使用Composer安装依赖项 - Unable to install dependencies with composer inside Docker image 摆脱foreach循环中损坏的图像? - Get rid of broken image in foreach loop? jQuery图像叠加(并摆脱imagecopymerge) - JQuery image overlay (and get rid of imagecopymerge) Docker PHP映像助手和构建依赖项 - Docker PHP image helpers and build dependenices 当我使用 docker multi-stage build 为生产构建应用程序时,如何删除 composer dev 依赖项? - How I can remove composer dev dependencies when I build my application for production using docker multi-stage build? 尝试从Docker Hub上的官方blackfire / blackfire映像为BlackFire构建本地Docker映像 - Trying to build a local Docker image for BlackFire from official blackfire/blackfire image on docker hub 如何在 docker 多阶段构建中从一个图像复制到另一个图像? - How to copy from one image to another in a docker multistaged build? 如何在 Jelastic jelastic/nginxphp 之上构建一个 docker 图像? - How to build a docker image on top of Jelastic jelastic/nginxphp?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM