简体   繁体   中英

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

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:

在此处输入图像描述

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM