rrmesquita
rrmesquita

Reputation: 706

Can't make docker-compose work like dockerfile

I'm trying to deploy a Nuxt.js application within a Docker container and in most of the tutorials, it is asked to create a Dockerfile with this content:

FROM node:alpine

ENV APP_ROOT /app

RUN mkdir ${APP_ROOT}
WORKDIR ${APP_ROOT}
ADD . ${APP_ROOT}

RUN npm install
RUN npm run build

ENV HOST 0.0.0.0

And then use this to build the actual image of the project, but this process takes too long because it needs to copy the whole project to the working directory. So i thought in writing all this in the docker-compose.yml file like so:

version: "3"

services:
  frontend:
    image: node:alpine
    container_name: website_frontend
    ports:
      - "3000:3000"
    environment:
      HOST: 0.0.0.0
    working_dir: /app
    volumes:
      - ./frontend:/app
    restart: always
    command: sh -c "npm install && npm run build && npm run start"

But it is not working as I get the status ERR_EMPTY_RESPONSE. What am I missing here?

Upvotes: 0

Views: 162

Answers (1)

Prashanth Sams
Prashanth Sams

Reputation: 21129

I did few changes in the above docker-compose.yml; if it doesn't work, there should be an issue with the npm build.

version: '3.7'

services:
  frontend:
    container_name: website_frontend
    image: node:alpine
    ports:
      - "3000:3000"
    environment:
      - HOST=0.0.0.0
    working_dir: /app
    volumes:
      - ./frontend:/app
    command: bash -c "npm install && npm run build && npm run start"
    restart: always

Upvotes: 1

Related Questions