Docker-compose: run tests with postgres

nodejs
docker
postgresql

#1

Hello,

I would like to run tests for my project by using docker directly. But when docker-compose starts the postgres container, I get an error: “Exited with code 254”.
Here are my configuration files:

Docker file:

FROM node:7.9

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY ./package.json /usr/src/app
RUN npm install

COPY . /usr/src/app

EXPOSE 3000 5858

ENTRYPOINT [ "npm", "start" ]

docker-compose.test.yml:

version: '2.0'
services:
  db:
    image: postgres
    expose:
      - 5432
    environment:
      POSTGRES_USER: myuser
      POSTGRES_PASSWORD: mypass
      POSTGRES_DB: db
  srv:
    build: .
    depends_on:
      - db
    volumes:
      - .:/app
    working_dir: /app
    ports:
      - "3000:3000"
    entrypoint: npm --silent run check-all
    environment:
      DATABASE_URL: postgres://myuser:mypass@db:5432/db

circle.yml:

version: 2
jobs:
  build:
    working_directory: ~/ci
    docker:
      - image: buildpack-deps:trusty
    steps:
      - checkout

      - setup_remote_docker

      - 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: Install Docker Compose
          command: |
            set -x
            curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
            chmod +x /usr/local/bin/docker-compose

      - run: 
          name: Build
          working_directory: ~/ci/server
          command: |
            set -x
            docker-compose -f docker-compose.test.yml build --no-cache 

      - run: 
          name: Run Tests
          working_directory: ~/ci/server
          command: |
            set -x
            docker-compose -f docker-compose.test.yml run srv

CircleCi error log:

#!/bin/bash -eo pipefail
set -x
docker-compose -f docker-compose.test.yml run srv
+ docker-compose -f docker-compose.test.yml run srv
Creating network "server_default" with the default driver
Pulling db (postgres:latest)...
latest: Pulling from library/postgres

Digest: sha256:fd6c0e2a9d053bebb294bb13765b3e01be7817bf77b01d58c2377ff27a4a46dc

Status: Downloaded newer image for postgres:latest

Creating server_db_1
Exited with code 254

Could you indicate me what am I doing wrong or what this error 254 means ?

Thanks a lot,


#2

Does the same docker-compose up work locally?


#3

Yes the same docker-compose “up” works. The “build” then “run” work locally as well.


#4

I think circle 2.0 does not support volumes . https://circleci.com/docs/2.0/building-docker-images/. Mouting volume part


#5

The base docker executor only supports docker cp but the machine executor does support volume mounting.


#6

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