I have a gatsby docker image which works as expected when run with docker run, but when I run it with docker-compose up I get the following error: 
There was a problem loading the local develop command. Gatsby may not be installed in your site's "node_modules" directory. Perhaps you need to run "npm install"? You might need to delete your "package-lock.json" as well. 
My Dockerfile looks like this:
FROM node:12-buster
RUN npm install --global gatsby-cli && gatsby telemetry --disable
WORKDIR /app
COPY package*.json /app/
RUN npm install --force
COPY . .
EXPOSE 8000
CMD ["npm", "run", "develop"]
The compose file looks like this:
   frontend:
    build: frontend
    image: frontend
    volumes:
      - ./frontend:/app
    ports:
      - "8000:8000"
    depends_on:
      - backend
The image will work fine when the code is in the context of build, because all commands RUN will be executed during docker build image process.
When you instance a image as you do on docker-compose, you are not running:
RUN npm install --force
because it was executed during build image time. No during launch container.
So, for solve your problem and considering how your image was built you need not to include a volume instead include your code as build context.
version: "3.7"
services:
  webapp:
    build:
      context: ./dir
      dockerfile: Dockerfile
https://docs.docker.com/compose/compose-file/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With