Search code examples
node.jsdockerdocker-composenext.jsyarnpkg

why is docker compose breaking my Next.js build


I have been developing an application with Next.js and PostgreSQL. I have 3 dockerfiles, one for my hosting my next.js app, and two for two PostgreSQL databases. I have no problem with any of them when running docker build and docker run, but when I tried setting up docker compose and the two database containers spin up fine but the Next.js server gives me

next start


/bin/sh: next: not found

Since the since docker-compose is working fine for the databases I am only including the Dockerfile and the part of docker-compose for the Next.js app.

Project structure:

App>
  DB>
  UI>
    pages>
    public>
    components>
    styles>
    .dockerignore
    Dockerfile
    package.json
    tsconfig.json
    yarn.lock
  .gitignore
  docker-compose.yml
  readme.md

Dockerfile:

#nodeJS on top of alpine linux
FROM node:alpine

#copy content of UI project directory into new /app directory in image
COPY . /app

#change working directory to /app
WORKDIR /app

#install dependencies and build app
RUN yarn && yarn build

#expose port 3000 
EXPOSE 3000

#Start app server upon docker run
CMD ["yarn", "start"]

docker-compose.yml

version: '3'
services:
    app:
        build: 
            context: ./UI
            dockerfile: Dockerfile
        volumes: 
            - ./UI:/app
        ports:
            - 4960:3000

can someone please help me identify what is wrong with my set up here? Like I said docker build and docker run have no issues at all so it must be something with my docker-compose file. Thank you!


Solution

  • Okay, about 30 seconds after posting this question I figure it out.

    This line was breaking everything and was completely unnecessary 😃

    volumes: 
        - ./UI:/app
    

    Walking away for a while and looking with fresh eyes always helps!