How to solve /bin/sh: 1: source: not found during making docker image in MacOS(Golang)?


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
# RUN go get
# RUN go get
# RUN go get
# RUN go get
# RUN go get
# 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
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


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

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

Answered By – goodahn

Answer Checked By – Marilyn (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.