jeudi 26 avril 2018

Docker container for app tests with postgres database

I'm new to Docker.

I'm trying to run my node app tests in a Docker container. I want to run the tests with a real postgres db. I'm creating this container with the following Dockerfile:

# Set image
FROM postgres:alpine
# Install node latest
RUN apk add --update nodejs nodejs-npm
# Set working dir
WORKDIR .
# Copy the current directory contents into the container at .
ADD src src
ADD .env.testing .env
ADD package.json .
ADD package-lock.json .

# Run tests
CMD npm install && npm run coverage

  1. From the image docs, when I run the container with:

    $ docker run build-name -d postgres

I see that the container takes time to start postgresql service.

  1. When I run the container without the "-d postgres" param:

    $ docker run build-name

The service does not start and the tests fail due to "could not connect to server".


Questions:

A. How can I run the tests AFTER the postgresql service starts?

B. I saw some examples using docker-composer but can I do this without composer?

Thanks

Aucun commentaire:

Enregistrer un commentaire