0

I have a project which includes a docker setup that I'm trying to get working. My Dockerfile is:

FROM node:8-alpine

EXPOSE 3000

ARG NODE_ENV
ENV NODE_ENV $NODE_ENV

RUN mkdir /app
WORKDIR /app
ADD package.json yarn.lock seed.js /app/
RUN yarn --pure-lockfile
ADD . /app

CMD ["yarn seed"]
CMD ["yarn", "docker:start"]

and my docker-compose:

version: "2"
services:
  isawyou-server:
    build: .
    environment:
      - MONGO_URI=mongodb://mongodb:27017/isawyou
    volumes:
      - .:/app
    ports:
      - "3000:3000"
    depends_on:
      - mongodb

  mongodb:
    image: mongo
    ports:
      - "27017:27017"

Now, for the docker-compose.test I am trying to set it up according to the instructions of https://docs.docker.com/docker-cloud/builds/automated-testing/ . I basically want to have a different database for testing. I tried different configs but none works. The error I get is:

     yarn run v1.3.2
$ docker-compose -f docker-compose.yml -f docker-compose.test.yml up --abort-on-container-exit
Starting server_mongodb_1 ...
Starting server_mongodb_1 ... done
Recreating server_sut_1 ...
Recreating server_sut_1
Starting server_isawyou-server_1 ...
Recreating server_sut_1 ... error

ERROR: for server_sut_1  Cannot start service sut: driver failed programming external connectivity on endpoint server_sut_1 (bbStarting server_isawyou-server_1 ... done

ERROR: for sut  Cannot start service sut: driver failed programming external connectivity on endpoint server_sut_1 (bbfc8b734ab6d4df2f3d3060245c81e0c88e945952dfe62c74f2aae6510d2cfe): Bind for 0.0.0.0:3000 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

my docker-compose.test currently looks like:

version: "2"
services:
  sut:
    build: .
    environment:
      - MONGO_URI=mongodb://mongodb:27017/isawyou
    volumes:
      - .:/app
    ports:
      - "3000:3000"
    depends_on:
      - mongodb
    command: yarn test

  mongodb:
    image: mongo
    ports:
      - "27017:27017"

2 Answers2

0

I think that you must add a database service to the docker-compose.test file. The instructions you've provided states that "You can define any number of linked services in this file. The only requirement is that sut is defined." so I think the mongodb service is missing in order to find the database required by your tests. I've looked for a sample of a docker-compose.test that may be useful to understand how it should work.

Miguel A. C.
  • 1,221
  • 10
  • 12
  • indeed. the original error was different and I tried fixing it but I think I broke it more. I refactored my question to represent the initial problem – George Katsanos Nov 22 '17 at 08:07
  • Have you tried to remove ports "3000:3000" section from the sut section? Maybe you're already using 3000 port and when you try to run the tests it cannot reuse that port, removing the ports section would not expose it. – Miguel A. C. Nov 23 '17 at 10:15
0

I needed to reference my mongo db URI with the mongo service name. This answer helped me: https://stackoverflow.com/questions/25828021/unable-to-connect-to-mongodb-running-in-docker-container