简体   繁体   English

是否可以在docker-compose文件中为DockerComposeContainer使用本地Docker映像?

[英]Is it possible to use a local Docker image in a docker-compose file for DockerComposeContainer?

In my docker-compose.yaml file I use the image "my-service" (among other remote images that work fine) 在我的docker-compose.yaml文件中,我使用图像“ my-service”(在其他工作正常的远程图像中)

version: "2"
services:
  myservice:
    image: my-service

Normally I build the "my-service" image with maven using the io.fabric8 docker-maven-plugin. 通常,我使用io.fabric8 docker-maven-plugin使用maven构建“ my-service”映像。

My Dockerfile: 我的Dockerfile:

FROM vertx/vertx3-alpine
ENV VERTICLE_HOME /opt/lib
ENV NAME my-service
ENV EXEC_JAR_NAME my-service.jar
COPY target/my-service-1.0-SNAPSHOT.jar $VERTICLE_HOME/$EXEC_JAR_NAME
COPY target/lib $VERTICLE_HOME
COPY src/main/resources/settings.json /etc/company/myservice/settings.json
ENTRYPOINT ["sh", "-c"]
CMD ["java -cp $VERTICLE_HOME/$EXEC_JAR_NAME com.company.myservice.MyVerticle"]

Is there a way using the DockerComposeContainer from Testcontainers for docker-compose to use my local image of my-service? 有没有办法使用Testcontainers的DockerComposeContainer来让docker-compose使用我的本地服务映像?

This is my test set up 这是我的测试设置

public class MyServiceIT {
    @ClassRule
    public static DockerComposeContainer compose =
            new DockerComposeContainer(new File("src/test/resources/docker-compose.yml"));

Currently I get the following error message as it is using local images. 目前,由于使用本地图像,我收到以下错误消息。

7:15:34.282 [tc-okhttp-stream-454305524] INFO 🐳 [docker/compose:1.8.0] - STDERR: pull access denied for my-service, repository does not exist or may require 'docker login'
17:15:34.283 [main] WARN org.testcontainers.containers.DockerComposeContainer - Exception while pulling images, using local images if available

It sounds like I need to build the image for use in my test, but I am not sure how to do that. 听起来我需要构建要在测试中使用的图像,但是我不确定该怎么做。

That's not an error message, but just a warning if docker-compose pull fails, see here . 那不是错误消息,而只是如果docker-compose pull失败的警告,请参阅此处

You can also make Docker Compose build the images for you (although it is highly recommended to use withLocalCompose(true) in that case) 您也可以让Docker Compose为您构建映像(尽管在这种情况下,强烈建议与withLocalCompose(true)一起使用)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM