5

I am just getting started learning docker a few hours ago and I trying to make my own docker image. When I tried to make a Dockerfile and a docker image, I got this error message "/bin/sh: 1: source: not found".

First of all, I manage my environment variables in .env file. Whenever I change my env file, I run this command $source .env and go build . and then go run main.go. So, I tried to set up my Dockerfile, RUN source.env but I got the error that I mentioned above.

I tried

  • RUN . setting.env & . setting but didn't work
  • change the file name into setting.env and then RUN . ./setting.env & . ./setting & ["/bin/bash", "-c", "source ~/.setting.env"] also didn't work...

I really appreciate your help!

Edit 1]

FROM golang:latest

WORKDIR /go/src/todo_list
# RUN go mod init github.com/jiwanjeon/go-todolist
# RUN go get github.com/jinzhu/gorm
# RUN go get github.com/lib/pq
# RUN go get github.com/gorilla/mux
# RUN go get github.com/stretchr/testify
# RUN go get github.com/jinzhu/gorm/dialects/postgres
# source .env --> . setting.env & . setting & . ./setting.env & . ./setting & ["/bin/bash", "-c", "source ~/.setting.env"]
RUN . .env
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY . ./

WORKDIR /go/src/todo_list/cmd/main
EXPOSE 9010
RUN go mod verify
RUN go build main.go
CMD ["./main", "-migrate"]
# RUN ./main -migrate

Edit 2]

I tried

  • RUN /bin/bash -c ". setting.env" / "source setting.env" : No such file or directory
JiwanJeon94
  • 385
  • 4
  • 12
  • 2
    Paste the Dockerfile here. – j4zzcat Feb 27 '22 at 10:54
  • 1
    `source` isn't a standard shell command. Some popular shells support it as an extension, but it's not part of the standard. Trying to read in files of environment variables like this in Docker also doesn't necessarily work well, since the environment will be reset after each `RUN` command. Further discussion in [Using the RUN instruction in a Dockerfile with 'source' does not work](https://stackoverflow.com/questions/20635472/using-the-run-instruction-in-a-dockerfile-with-source-does-not-work). – David Maze Feb 27 '22 at 11:55
  • Try using the ENV command, if you want to run a script to set up an environment. – Goffity Feb 27 '22 at 12:24
  • @j4zzcat Could you check my Edit part?? – JiwanJeon94 Feb 28 '22 at 00:26
  • @DavidMaze Thank you for your detailed answer! I checked your link and read it! I am not sure what part is wrong... – JiwanJeon94 Feb 28 '22 at 00:34
  • @Goffity Thank you for your comment! Did you mean this link? https://docs.docker.com/engine/reference/builder/#env – JiwanJeon94 Feb 28 '22 at 00:37
  • @DavidMaze I think the reason why I couldn't follow your link solution is the default base image for Ubuntu 12.04. I am currently sitting in Mac OS. I am not this is the main reason or not... – JiwanJeon94 Feb 28 '22 at 00:54

1 Answers1

1

It seems like .env file is not contained in your image.

Try to execute source .env after copying .env file into the image.

goodahn
  • 195
  • 7