0

I know that there has been others who have asked this question on here before, however, I have gone through them and have tried the suggestions. I believe that its a complex issue because everyone's files look different and varies from the other based on placements and paths, which I am not familiar yet in Docker. Now, when I run on docker-compose build, the program tells me that

Building server

Traceback (most recent call last): File "compose/cli/main.py", line 67, in main File "compose/cli/main.py", line 126, in perform_command File "compose/cli/main.py", line 302, in build File "compose/project.py", line 468, in build File "compose/project.py", line 450, in build_service File "compose/service.py", line 1147, in build compose.service.BuildError: (<Service: server>, {'message': 'Cannot locate specified Dockerfile: ./client/Dockerfile'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "docker-compose", line 3, in File "compose/cli/main.py", line 78, in main TypeError: can only concatenate str (not "dict") to str [34923] Failed to execute script docker-composeenter image description here

I have tried placing the Dockerfile from the client to the same directory as the docker-compose.yml file to eliminate path discrepencies, however, it still says the same thing. Please let me know if you have any suggestions. Thanks!

Here is my docker-compose.yml file

version: "3.7"

services:
  server:
    build:
      context: ./server
      dockerfile: ./client/Dockerfile
    image: myapp-server
    container_name: myapp-node-server
    command: /usr/src/app/node_modules/.bin/nodemon server.js
    volumes:
      - ./server/:/usr/src/app
      - /usr/src/app/node_modules
    ports:
      - "5050:5050"
    depends_on:
      - mongo
    env_file: ./server/.env
    environment:
      - NODE_ENV=development
    networks:
      - app-network
  mongo:
    image: mongo
    volumes:
      - data-volume:/data/db
    ports:
      - "27017:27017"
    networks:
      - app-network
  client:
    build:
      context: ./client
      dockerfile: Dockerfile
    image: myapp-client
    container_name: myapp-react-client
    command: npm start
    volumes:
      - ./client/:/usr/app
      - /usr/app/node_modules
    depends_on:
      - server
    ports:
      - "3000:3000"
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

volumes:
  data-volume:
  node_modules:
  web-root:
    driver: local

Here is the Dockerfile in the client folder

FROM node:10.16-alpine

WORKDIR /usr/src/app

COPY package.json ./

RUN npm install 

COPY . .

EXPOSE 3000

CMD ["npm", "start"]

Here is the Dockerfile in the server folder

FROM node:10.16-alpine

# Create App Directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install Dependencies
COPY package*.json ./

RUN npm install --silent

# Copy app source code
COPY . .

# Exports
EXPOSE 5050

CMD ["npm","start"]
Progman
  • 16,827
  • 6
  • 33
  • 48
UI Developer
  • 167
  • 6
  • 16
  • did you mean to have `context: ./server` and `dockerfile: ./client/Dockerfile` in the server's compose service? I think that's the issue since Docker should look for your dockerfile in the context. – cam Jan 30 '21 at 20:38

1 Answers1

0

EDIT 1: The issue was having an unusual path to the dockerfiles: client/docker-mern-basic. You can see this in the VSCode file explorer for the client paths. Resolved by making paths and context/dockerfile paths consistent, eliminating the extra docker-mern-basic path. See comments below.

EDIT 0: this doesn't solve the issue, I'll remove this if I can't find any other possible issues.

Your path for the server.build.dockerfile isn't relative to your context. You're providing the folder to use as "root" as server so Docker is actually looking for the path ./server/client/Dockerfile.

I think your issue is not giving a path relative to your context:

services:
  server:
    build:
      context: ./server
      dockerfile: Dockerfile
cam
  • 4,409
  • 2
  • 24
  • 34
  • Hi, thanks for your input. That was actually what I had originally and it gave me the same error. I just tried it again and same outcome – UI Developer Jan 30 '21 at 20:50
  • My bad, I think you said that in your post too. I'll take a closer look! – cam Jan 30 '21 at 20:53
  • Thanks, I appreciate it! – UI Developer Jan 30 '21 at 20:58
  • @kennyman335 From VSCode, it looks like your actual path is `client/docker-mern-basic` and your `docker-compose.yml` is in the root of your folder. Are you sure that the path to the 'root' of your files isn't `client/docker-mern-basic` at least for the client? Sorry, I can't tell the paths from VSCode but it looks like this could be the issue. – cam Jan 30 '21 at 20:58
  • It seems as if the path is /Documents/Projects/react/docker-mern-basic/client/docker-mern-post. Im not sure why it did that as i dont see the docker-mern-post directory in VScode – UI Developer Jan 30 '21 at 21:07
  • I found a solution. All i did was take out the folder that was holding the react app itself(docker-mern-post) and pull it into the root directory.Then I specified the path to the docker file which was in the docker-mern-post folder(the folder holding react). Afterwards, in the docker-compose.yml file, I specified the client context path to the dockerfile. Thanks for your help! – UI Developer Jan 30 '21 at 21:41
  • I found a solution. All i did was take out the folder that was holding the react app itself(docker-mern-post) and pull it into the root directory.Then I specified the path to the docker file which was in the docker-mern-post folder(the folder holding react). Afterwards, in the docker-compose.yml file, I specified the client context path to the dockerfile. Thanks for your help! – UI Developer Jan 30 '21 at 21:42
  • Great! It seemed like there was a weird path issue. Glad you figured it out. – cam Jan 30 '21 at 21:46