Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose directory to build in path

I'm trying to split up my application into two docker services - frontend and backend, where my project layout looks similar to this.

| frontend
|  - ...
|  - Dockerfile.prod
| backend
|  - ...
|  - Dockerfile.prod
| docker-compose.yml

Till this point, I've only written the dockerfile for frontend

FROM node:13.12.0-alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm ci --silent
RUN npm install [email protected] -g --silent
COPY . ./
RUN npm run build

FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

What bothers me is that when Im running that image standalone everything works flawlessly, but when I try to throw it into the docker-compose.yml file this error kick in

$  docker-compose.exe up -d --build
Building frontend
Traceback (most recent call last):
  File "docker-compose", line 6, in <module>
  File "compose\cli\main.py", line 72, in main
  File "compose\cli\main.py", line 128, in perform_command
  File "compose\cli\main.py", line 1077, in up
  File "compose\cli\main.py", line 1073, in up
  File "compose\project.py", line 548, in up
  File "compose\service.py", line 351, in ensure_image_exists
  File "compose\service.py", line 1106, in build
  File "site-packages\docker\api\build.py", line 148, in build
TypeError: You must specify a directory to build in path
[12540] Failed to execute script docker-compose

I've browser the similar questions but none of their suggestions seemed to work on my scenario for some reason.

this is my docker-composer file

version: '3'

services:
  frontend:
    container_name: react-prod
    build:
      context: .
      dockerfile: frontend/Dockerfile.prod
    ports:
      - 6666:80
like image 951
Terchila Marian Avatar asked Apr 23 '20 04:04

Terchila Marian


1 Answers

In your Dockerfile for the frontend you are copying using a relative path: COPY . ./.

When you build using docker-compose the context you gave is going to be . and not the actual frontend directory with the Dockerfile in it. So I am just suggesting that maybe you in the docker-compose.yml instead of:

    build:
      context: .
      dockerfile: frontend/Dockerfile.prod

You should have:

    build:
      context: ./frontend
      dockerfile: Dockerfile.prod
like image 162
jamomani Avatar answered Oct 06 '22 10:10

jamomani