Home > Blockchain >  app in Docker container can't locate csv file in root directory?
app in Docker container can't locate csv file in root directory?

Time:07-16

My app inside a container is trying to open a csv file, os.Open("file.csv") , however it cannot locate the csv file inside root directory of my project, it's not being copied over...

My project set up, here is the root of my project

Dockerfile
health-check/  # This is where the code for my app is, inside this folder
file.csv # File that app needs to open is in the root directory. 
          

Here is my Dockerfile

# syntax=docker/dockerfile:1

##
## Build
##
FROM golang:1.18-buster AS build

WORKDIR /app

COPY health-check/ .
RUN go mod download

RUN go build -o /health-check-ping

##
## Deploy
##
FROM gcr.io/distroless/base-debian10

WORKDIR /

COPY --from=build /health-check-ping /health-check-ping

EXPOSE 8080

USER nonroot:nonroot

ENTRYPOINT ["/health-check-ping"]

How can I fix my dockerfile so have my CSV file copied over so my app can open is

EDIT:

enter image description here

I have moved the csv file to health-check/ and replaced the way my app opens the file by doing the following: os.Open("/app/health-check/challenge_dataset.csv")

My container log is throwing back this error: open /app/health-check/challenge_dataset.csv: no such file or directory

CodePudding user response:

the problem is you don't copy the csv file to your docker. when using FROM you change the image you are building so your copy become not relevant. you need to have COPY health-check/ /app after the last FROM (worked when written the line before the EXPOSE).

  • Related