How to solve the error, while running "docker build" on macOS terminal

trying to build Docker on my Mac. On Windows I did the same thing and it worked perfectly. But on Mac, I am getting this issue. I have tried “docker build –add-host=docker:10.180.0.1 . ” to fix this but I am not quite sure why this thing is happening. since I am new in docker, maybe on Mac it needs some other setting than Windows. I also tried to run from root user, but failed.

[email protected] project-dev % docker-compose up --build
Building app-server
Step 1/11 : FROM nandi/repo::java8-mvn3.6.3
 ---> 04c656608134
Step 2/11 : WORKDIR /app
 ---> Using cache
 ---> 9b4331e87e33
Step 3/11 : VOLUME /tmp
 ---> Using cache
 ---> 36fadbc0c29d
Step 4/11 : COPY pom.xml .
 ---> Using cache
 ---> e7f7473d02dc
Step 5/11 : RUN mvn dependency:go-offline -B
 ---> Using cache
 ---> 16ae4850a759
Step 6/11 : COPY src src
 ---> Using cache
 ---> 5ac483e4387e
Step 7/11 : COPY additional/ /root/.repo/
 ---> Using cache
 ---> 9e64ba793eed
Step 8/11 : RUN mvn package -DskipTests
 ---> Using cache
 ---> d79346f68d6a
Step 9/11 : RUN mkdir /root/fsys
 ---> Using cache
 ---> 2277a5cb0349
Step 10/11 : COPY known_hosts /root/.ssh/known_hosts
ERROR: Service 'app-server' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder412226086/known_hosts: no such file or directory

my Dockerfile:

### Should only be used with mvn dockerfile:build
### Simple docker build . will produce errors

FROM nandi/repo:java8-mvn3.6.3
WORKDIR /app

VOLUME /tmp

# Build all the dependencies in preparation to go offline.
# This is a separate step so the dependencies will be cached unless
# the pom.xml file has changed.
COPY pom.xml .

RUN mvn dependency:go-offline -B

# Copy the project source
COPY src src

# Package the application
COPY additional/ /root/.repo/
RUN mvn package -DskipTests
RUN mkdir /root/fsys
COPY known_hosts /root/.ssh/known_hosts

##### Stage 2: A minimal docker image with command to run the app
#FROM openjdk:8-jre-alpine
#
#ARG DEPENDENCY=/target/dependency
#
## Copy project dependencies from the build stage
#COPY --from=build ${DEPENDENCY}/ /app/
##COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
##COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app

ENTRYPOINT ["java","-jar", "target/repo-1.0-SNAPSHOT.jar"]

what could be the possible solution for this? thanks in advance 🙂

Source: StackOverflow