Multi-Image Docker for Databases Images Failing

postgresql

#1

Hello,

I created several Docker images with mock data that I’m trying to run inside CircleCI (2.0), so my tests have a database to connect to. I ended up going down the route of a multi-image setup:

  build:
    docker:
      - image: circleci/node:7.10
      - image: private_repo/postgres:latest

Where the Postgres Docker image is a custom image (postgres:9.6.1-alpine base) with pre-loaded data (multi-stage Docker image where data is restored, and the resulting data directory is copied to a fresh Postgres image).

My issue is that while the custom Postgres image runs fine on my own device, it appears to have issues when being run inside CircleCI as a secondary image. I see a lot of lines like this output:

could not remove cache file "global/pg_internal.init": Permission denied

Again, these issues do not occur when I run this image elsewhere. Any ideas?

Extra: this is how I generate the custom Postgres image with pre-loaded data:

FROM postgres:9.6.1-alpine AS donor
ADD VERSION .
ENV PGDATA=/pgdata
RUN mkdir /tmp/insert-data
COPY "data-fetch/data/*" "/tmp/insert-data/"
COPY "image_extend/*" "/docker-entrypoint-initdb.d/"
RUN chmod 755 /docker-entrypoint-initdb.d/*.sh
RUN /docker-entrypoint.sh --help #all the data is loaded to this instance

FROM postgres:9.6.1-alpine
ENV PGDATA=/pgdata
COPY --from=donor /pgdata /pgdata

#2

It ended up being a permission issue within the Postgres image - not CircleCI related at all!


#3

@kbarresi How did you end up resolving the permission issue? I’m running into the same problem now.


#4

I don’t remember exactly what I did, but we have a write-up on our engineering blog of how we did this. Let me know if that helps: https://medium.com/fintech-studios-engineering/creating-fast-lightweight-testing-databases-in-docker-2a8164d2f519


#5

@kbarresi Thanks! Your post is really helpful! The key was to use the --chown flag in the last COPY command.


#6

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.