简体   繁体   English

Docker:如何在精简的“无发行版”映像中运行多个二进制文件?

[英]Docker: how to run multiple binaries in a stripped-down "distroless" image?

I have a Dockerfile that is currently using amazonlinux as the base image.我有一个 Dockerfile 目前正在使用 amazonlinux 作为基础映像。

The purpose of the image is to run two binaries in the container.映像的目的是在容器中运行两个二进制文件。 Consequently, the CMD instruction of the Dockerfile currently looks like this:因此,Dockerfile 的 CMD 指令当前如下所示:

CMD [ "/bin/sh", "-c", "/binary1 & /binary2"]

I am looking to modify this Dockerfile to migrate it to a "distroless" image.我希望修改此 Dockerfile 以将其迁移到“无发行版”映像。 This entails modifying the Dockerfile FROM to be built on top of a stripped-down base image (which will itself be Linux-based).这需要修改 Dockerfile FROM 以构建在精简的基础映像(其本身将基于 Linux)之上。

My problem is that this new stripped-down base image will no longer contain the "&" that previously came with the shell in the prior Linux image.我的问题是,这个新的精简基础映像将不再包含先前 Linux 映像中 shell 附带的“&”。 It does not have "&&" either, or for that matter any operator that would enable me to run both binaries from within the Dockerfile.它也没有“&&”,或者就此而言,任何可以让我从 Dockerfile 中运行两个二进制文件的运算符。

I am wondering if there is some way to run multiple binaries in a stripped down image like this?我想知道是否有某种方法可以在这样的精简图像中运行多个二进制文件?

For example, perhaps I can install the files containing "&", "&&", or some similar command in my Dockerfile to accomplish this, since the new "distroless" image will still be Linux based?例如,也许我可以在我的 Dockerfile 中安装包含“&”、“&&”或某些类似命令的文件来完成此操作,因为新的“无发行版”映像仍将基于 Linux? If so, how can I determine which specific files I would need, and how can I install them?如果是这样,我如何确定我需要哪些特定文件,以及如何安装它们?

Any pointers would be appreciated, as I am quite new to Docker.任何指针都会受到赞赏,因为我对 Docker 很陌生。

Any pointers would be appreciated, as I am quite new to Docker.任何指针都会受到赞赏,因为我对 Docker 很陌生。

In general, don't try running multiple binaries in a single container like this.一般来说,不要尝试像这样在单个容器中运行多个二进制文件。 In almost all cases, it is more flexible and management to run two separate containers: so if you were to build a "distroless" image containining your two binaries, you would start two containers from the same image (eg docker run myimage binary1 and docker run myimage binary2 ).在几乎所有情况下,运行两个单独的容器更加灵活和管理:因此,如果您要构建包含两个二进制文件的“无发行版”映像,您将从同一个映像启动两个容器(例如docker run myimage binary1docker run myimage binary2 )。

When you do something like...当你做类似...

CMD [ "/bin/sh", "-c", "/binary1 & /binary2"]

...you have made failures of binary1 invisible to Docker: if the command fails, your container will merrily keep running, and you can't use a restart policy to restart it for you automatically. ...您已使 Docker 看不到binary1的故障:如果命令失败,您的容器将继续运行,您不能使用重启策略自动为您重启它。


Alternately, if you really want to do the thing you're trying to do, rather than using a "distroless" base image, consider instead using a minimal image like busybox or alpine : these will provide you with a shell and common unix utilities for debugging work, but are still quite small.或者,如果您真的想做您想做的事情,而不是使用“无发行版”基础映像,请考虑使用像busyboxalpine这样的最小映像:这些将为您提供 shell 和常见的 unix 实用程序调试工作,但仍然很小。

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

相关问题 如何为从二进制文件安装的 docker 配置 systemctl 服务? - How to configure systemctl service for docker installed from binaries? 从 firecracker 的 distroless 镜像构建一个 rootfs ext4 镜像 - Build a rootfs ext4 image from distroless image for firecracker docker run说“没有这样的图像” - docker run says “No such image” 如何在Ubuntu 10.10中的NTFS上运行C ++二进制文件? - How to run C++ binaries on NTFS in Ubuntu 10.10? 如何运行 httpd:2.4-alpine docker 映像不是 root 用户 - How to run httpd:2.4-alpine docker image not as root user 詹金斯码头工人缺少一些二进制文件 - Jenkins docker missing some binaries 如何在linux中编译二进制文件,可以在没有前面的情况下运行./ - how to compile binaries in linux which can be run without preceding ./ 如何在最小的linux安装上“停靠运行”shell会话并立即拆除容器? - how to “docker run” a shell session on a minimal linux install and immediately tear down the container? Docker:如何创建堆栈,多个图像或一个基本映像? - Docker: How to create a stack, multiple images or one base image? 如何通过交叉编译为多个平台构建 docker 图像? - How to build docker image for multiple platforms with cross-compile?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM