Hi all,
I am facing an interesting problem with testcontainers. I am using the DockerComposeContainer class to start a container for a docker-compose.yml configuration as following:
DockerComposeContainer c = new DockerComposeContainer(... path to docker-compose.yml ...).withLocalCompose(false);
c.starting(null);
Please note the withLocalCompose(false), as it is important.
This works great on my host. However, when my application is started in a docker container, this doesn't work. I am starting my container as following:
docker run -v /var/run/docker.sock:/var/run/docker.sock:ro my-image
Why?
In my-image, the docker-compose.yml is in /app. Now, when c.starting(null) is called, a new child docker-compose container is started, as per withLocalCompose(false). This container is executed in the host, as per -v /var/run/docker.sock:/var/run/docker.sock:ro. But, in my host, there is no /app/docker-compose.yml.
How can we solve this?
One possible solution might be to read and parse /app/docker-compose.yml before starting the child docker-compose container? Either this could be done by (ideally) testcontainers or by myself. In the case of the latter, I should be able to provide the contents of /app/docker-compose.yml to the constructor of DockerComposeContainer.
However, I am not sure if this is the best solution, as I don't have any idea if this is supported by components upstream.
Any ideas?
Thank you!