Docker构建找不到运行测试的Docker [英] Docker build can't find docker to run tests

查看:84
本文介绍了Docker构建找不到运行测试的Docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NodeJS应用程序,该应用程序使用 ioredis 连接到Redis并发布数据和其他Redy东西。

I have a NodeJS application that is using ioredis to connect to redis and publish data and other redisy things.

我正在尝试针对redis编写组件测试,并能够通过开玩笑创建一个安装/拆卸脚本,该脚本通过docker在随机端口上运行redis并将其拆解在通过 docker run -d -p 6379 --rm redis docker stop {containerId} 完成测试时。

I am trying to write a component test against redis and was able to create a setup/teardown script via jest that runs redis via docker on a random port and tears it down when the tests are done via docker run -d -p 6379 --rm redis and docker stop {containerId}.

这在本地很不错,但是我们的测试在Dockerfile中的多阶段构建中运行:
RUN yarn test

This works great locally, but we have the tests running in a multi-stage build in our Dockerfile: RUN yarn test

我尝试通过 docker build进行构建。直到进行测试,然后抱怨以下错误- / bin / sh:docker:找不到

which I try to build via docker build . it goes great until it gets to the tests and then complains with the following error - /bin/sh: docker: not found

因此,docker无法在docker-build进程中运行测试吗?

Hence, Docker is unavailable to the docker-build process to run the tests?

是否有一种方法可以运行docker-build使其具有加速兄弟姐妹的能力

Is there a way to run docker-build to give it the ability to spin up sibling processes during the process?

推荐答案

这对我来说就像是码头工人。

This smells to me like a "docker-in-docker" situation.

您不能旋转兄弟姐妹,但是可以通过一些技巧在容器中生成一个容器:(您可能需要做一些谷歌搜索才能使它正确)

You can't spin up siblings, but you can spawn a container within a container, by doing some tricks: (you might need to do some googling to get it right)


  • 在主机容器中安装docker二进制文件

  • 从主机容器,例如 docker run -v /var/run/docker.sock:/var/run/docker.sock ...

  • install the docker binaries in the "host container"
  • mount the docker socket from the actual host inside the "host" container, like so docker run -v /var/run/docker.sock:/var/run/docker.sock ...

但是您将无法在构建步骤中执行此操作,因此这对您的情况而言并不容易。

But you won't be able to do it in the build step, so it won't be easy for your case.

我建议您准备一个能够运行嵌套容器的专用构建容器,该容器将基本上模拟您的本地环境并在CI中使用它。尽管如此,您可能仍需要重构一下才能使其正常工作。

I suggest you prepare a dedicated build container capable of running nested containers, which would basically emulate your local env and use that in your CI. Still, you might need to refactor your process a bit make it work.

祝您好运:)

这篇关于Docker构建找不到运行测试的Docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆