2

We're heavily using docker for integration testing and to reduce the setup times for the test environment, we'd like to create images that already contain test data to a certain extend.

For some services we rely on public docker images, that define volumes where data is stored.

I've observed, that docker does not persist data that is stored in these volume mounts (defined by the base image) during build. There are also questions around this issue like this, this or this issue.

Now given that it's the way how docker works, I wonder what would be a good approach to work around this issue?

This question here describes, how I could pre-populate a volume with data from the image - which is kind of the opposite of what I'd like to achieve.

Currently I'm setting up the images and move the pre-populated data from the volume mount to another directory at the end of the build. And on container start I link every subfolder back into the volume mounts. But this is kind of ugly as I have to link every subfolder seperately, because the parent folder is the volume mount and can not be linked.

Are there better ways? Is there even an "official" docker way to achive this?

Gerald Mücke
  • 10,724
  • 2
  • 50
  • 67

2 Answers2

0

You could create a new docker image to store your test-cases and test-data already built into it. This could be built either with or without your test-application.

Later you can decide if you want to run it as a separate container to test temporary stuff or as part of a multi-stage test image creation, something like:

FROM alpine:latest
# Start from your vendor image

# Copy your test-data to your container
COPY test-data1 /usr/test-data/case1
COPY test-data2 /usr/test-data/case2

# Add what you need to execute..
CMD [./execute-test]

Then you can run the container without even any volumes and emit the results as needed or you can use multi-stage builds, to capture your test-data in one image and build your test-app on top of it in two stages:

FROM mytest-data:latest # Image created as the previous step

FROM mytest-app:latest # Your test-application
WORKDIR /usr/test-data
RUN ./test-app # to execute and capture test results in the build phase

Either ways, I recommend to upload the custom images into your own image reposiroty, like AWS ECR or Artifactory, etc..

muratiakos
  • 1,064
  • 11
  • 18
0

Your remark "For some services we rely on public docker images, that define volumes where data is stored." seems to be related to the question that it is not possible to "undeclare" a volume. I have bumped into that problem as well when taking over production images into a testing setup - and lately I have created a workaround that can help with that situation. (docker-copyedit).

Guido U. Draheim
  • 3,038
  • 1
  • 20
  • 19