0

I have got a prisma server image from dockerhub which is

prismagraphql/prisma:1.34

The above prisma image in order to run on PORT 4466 requires database connection string and the same is passed as an environment variable using a docker-compose file like shown below

prisma:
   image: prismagraphql/prisma:1.34   
   ports:
     - "4466:4466"     
   environment:
     PRISMA_CONFIG: |
       port: 4466
       databases:
         default:
           connector: mongo
           uri: mongodb://mongodb   

I am trying to extend the above prisma server image like shown below.

FROM prismagraphql/prisma:1.34

RUN apk add  --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.7/main/ nodejs=8.9.3-r1

WORKDIR /project

COPY . .

# To handle 'not get uid/gid' error in alpine linux set unsafe-perm true
RUN apk update && apk upgrade \
    && npm config set unsafe-perm true \
    && npm install --g yarn \
    && npm install -g prisma \
    && yarn install \
    && chmod +x ./entrypoint.sh \
    && chmod +x ./wait-for-it.sh

EXPOSE 4466 4000

ENTRYPOINT ["./entrypoint.sh"]

The entrypoint.sh file is like this

#!/bin/bash

# wait for the prisma service to start.
# then run prisma deploy (more on that later)
./wait-for-it.sh prisma:4466 -- prisma deploy

# go into the project...
cd /project

# run an npm command to use nodemon to start/watch the server
npm run start

In the above Dockerfile

  • I try installing nodejs app on existing prisma image from dockerhub.

  • This nodejs application is called prisma nexus. nexus requires to be connected to prisma on localhost:4466 and nexus runs on port 4000.

When I run the below below image I get this error. i.e nexus(nodejs app) is not able to connect to prisma

Could not connect to server at http://localhost:4466. Please check if your server is running.

Finally I run the extended image like this


 mongodb:
   image: mongo:4.2
   container_name: mongodb
   volumes:
     - ./mongo-volume:/data/db
   ports:
     - "27017:27017"
   networks:
     - prisma

  prisma:
   image: extended-image-here:1.0
   container_name: prisma-server
   restart: always
   ports:
     - "4466:4466"
     - "4000:4000"
   environment:
     PRISMA_CONFIG: |
       port: 4466
       databases:
         default:
           connector: mongo
           uri: mongodb://mongodb

What am I doing here? Please help.

jeril
  • 1,109
  • 2
  • 17
  • 35
  • How do you run you extended image? – Sniper Mar 21 '20 at 09:07
  • using docker-compose.. I have updated the question on how I run the extended image – jeril Mar 21 '20 at 09:15
  • Did you try running nexus nodejs app with just the prisma image? I mean running nodejs app locally (not in a container) – Sniper Mar 21 '20 at 09:19
  • yes I tried running nodejs app within the container. I used ENTRYPOINT ["./entrypoint.sh"]. Updated the code of entrypoint.sh. entrypoint.sh calls another script ./wait-for-it.sh which checks whether prisma is ready on port:4466 and starts the nodejs app within the container – jeril Mar 21 '20 at 09:26
  • 1
    what is the content of `./wait-for-it.sh` – Al-waleed Shihadeh Mar 21 '20 at 09:26
  • wait-for-it.sh is a pure bash script that will wait on the availability of a host and TCP port. It is useful for synchronizing the spin-up of interdependent services, such as linked docker containers. Since it is a pure bash script, it does not have any external dependencies. https://github.com/vishnubob/wait-for-it – jeril Mar 21 '20 at 09:27
  • No, meant, just run the first docker compose file contianing only prisma(not the extended) then try to connect your nexus by manually npm start on your local machine and not inside any container. Do you still get the same error? – Sniper Mar 21 '20 at 09:33
  • No I do not want to do that.. I want to combine both prisma image and nodejs into a single image. There is a situation wherein I have to install this application in multiple machines and if I can combine both these services into a single image it would be easier for me – jeril Mar 21 '20 at 09:36
  • it seems that this line is not working as expected `./wait-for-it.sh prisma:4466 -- prisma deploy` . for some reason your still liked to the localhost and not `prisma`. – Al-waleed Shihadeh Mar 21 '20 at 10:42
  • wait a sec , in the `prisma` docker container you are implementing a wait for the ` `prisma` container. That sounds like a loop – Al-waleed Shihadeh Mar 21 '20 at 10:45
  • will check removing this script.. but I think the main reason it fails is because it has multiple entrypoints. The main prisma base image has an entrypoint like this "/bin/sh -c /app/staâ¦" and the above Dockerfile has an entrypoint like this ENTRYPOINT ["./entrypoint.sh"]. So the last entrypoint overrides the entrypoint of the base image. This makes ./wait-for-it.sh to keep waiting since prisma:4466 is not running – jeril Mar 21 '20 at 10:51
  • You don't need wait-for-it.sh -- compose has a built-in dependency mechanism. – Software Engineer Mar 21 '20 at 15:31

2 Answers2

0

I guess the reason why it does not work is because the image prismagraphql/prisma:1.34 has an entrypoint and at the end of the Dockerfile there is another entrypoint. Docker accepts only a single entrypoint in a Dockerfile...

jeril
  • 1,109
  • 2
  • 17
  • 35
0

First: In your code, you put the MongoDB container on a specific named network called prisma but you do not do the same thing with the prisma container. When using compose, containers on the same overlay network are resolved by name, but requests will only be routed between containers if they're on the same network.

Next: you shouldn't be running two servers in the same container. It's better to not build your app on top of the prisma image at all, but to build it instead on top of alpine or ubuntu (or anything else really). It should connect to another container where the prisma server is running. In the comments you say that you really want to do this, but you really shouldn't. It's not much harder to run a compose configuration on a client's server rather than a single container, but it is that much harder to run 2 servers in a single container.

Finally: The localhost reference (nexus you say?) should be configurable in some way. Find out how, and have it address something like 'http://prisma:4466'. In this way you'll have 3 containers -- mongodb, prisma, and your own app.

Software Engineer
  • 15,457
  • 7
  • 74
  • 102