Accessing database inside a docker container

docker
circle.yml

#1

Hi guys,
I’m having a couple of issues here:

  1. Can’t access the db inside of a container after I build it. I can access the db ok on the host. Here is a config file:
build_and_deploy:
    working_directory: ~/code
    docker:
      - image: unicef/etools:test-base
        environment:
          PGHOST: 0.0.0.0
          DATABASE_URL: "postgis://postgres:postgres@localhost:5432/circle_test"
      - image: circleci/postgres:9.5-alpine-postgis
        environment:
          POSTGRES_USER: postgres 
          PGUSER: postgres
          POSTGRES_DB: circle_test
          POSTGRES_PASSWORD: postgres
    steps:
      - checkout
      - setup_remote_docker:
          reusable: true
          exclusive: true
      - run:
          name: Install Docker client
          command: |
            set -x
            VER="17.03.0-ce"
            curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz
            tar -xz -C /tmp -f /tmp/docker-$VER.tgz
            mv /tmp/docker/* /usr/bin
      - run:
          name: Postgres Extensions
          command: |
            psql -U postgres -d template1 -c 'create extension if not exists hstore;'
      - run:
          name: see if postgres is available locally
          command: |
            pg_isready
      - run:
          name: Building the image
          command: |
            TAG=${CIRCLE_BRANCH}
            docker build -t unicef/etools:$TAG .
      - run:
          name: Test in the container
          command: |
            TAG=${CIRCLE_BRANCH}
            HOSTIP=`ip -4 addr show scope global dev eth0 | grep inet | awk '{print \$2}' | cut -d / -f 1`
            docker run -it -e "DATABASE_URL=postgis://postgres:postgres@docker:5432/circle_test" -e SECRET_KEY --add-host=docker:${HOSTIP} unicef/etools:$TAG bash runtests.sh
  1. Even though I’m using a circleci image the db does not persist… I’m trying to avoid re-running migrations on every test (takes a few good extra minutes every time), I’d love to be able to persist my test db between builds.

  2. From what I’ve read the following config is supposed to store the layers of the image and reuse them on next build, however my layers are never stored… so every time I try to re-build the image it starts from scratch.

 - setup_remote_docker:
          reusable: true
          exclusive: true

I’m not sure if this is the correct format to ask these questions … but can anyone help me? :slight_smile:

thanks


#2

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