Hello Community,
I already look at those issues : https://github.com/testcontainers/testcontainers-java/issues/842 and https://github.com/testcontainers/testcontainers-java/issues/668 but non of them fix my problem.
So basically I have the same problem mentionned in those issues but I'm not inside a container, I'm simply on windows.
Here is the code I use to define my container :
@ClassRule
public static OracleContainer oracleContainer =
(OracleContainer) new OracleContainer()
.withClasspathResourceMapping("init.sql",
"/docker-entrypoint-initdb.d/init.sql",
BindMode.READ_WRITE);
When I stop my test (debug mode) and go to the running container here is what I get :
root@a64a8dacd7a3:/docker-entrypoint-initdb.d# ls -la
total 8
drwxr-xr-x 1 root root 4096 Aug 29 09:23 .
drwxr-xr-x 1 root root 4096 Aug 29 09:23 ..
drwxr-xr-x 2 root root 40 Aug 29 09:11 init.sql
So my file is now a folder and my DB is not configured correctly.
I saw that on windows we probably need absolute path : https://stackoverflow.com/questions/34134343/single-file-volume-mounted-as-directory-in-docker
Is there any way to adapt testcontainer in that way ? Or should I proceed diferently ?
Technical Infos :
OS : Windows 10
Java version : 1.8.144
TestContainer version : 1.8.3
Hi @McKratt!
Try:
.withCopyFileToContainer(MountableFile.forClasspathResource("init.sql"), "/docker-entrypoint-initdb.d/")
This way there will be no file mounting at all :)
@bsideup Thank you for your quick answer, It's working now.
Can you point me the differences between the two with ?
@McKratt withCopy*** will copy the file (as InputStream) at container start-up while withClasspathResourceMapping maps the file as volume and requires you to run Docker on your machine, configure host mappings when you run Docker for Mac/Windows, etc
@bsideup Ok, so the with copy is more like a COPY from Dokerfile and the withClasspath is a -v option of the docker run command.
Thank you very much for those precisions ;-)