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

huangapple go评论97阅读模式
英文:

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

问题

我刚刚开始学习Docker几个小时前,我试图制作自己的Docker镜像。当我尝试创建Dockerfile和Docker镜像时,我遇到了这个错误信息"/bin/sh: 1: source: not found"。

首先,我在.env文件中管理我的环境变量。每当我更改.env文件时,我运行这个命令$source .env,然后运行go build .,最后运行go run main.go。因此,我尝试设置我的Dockerfile,使用RUN source.env,但是我得到了上面提到的错误。

我尝试了以下方法:

  • RUN . setting.env & . setting,但是没有起作用
  • 将文件名更改为setting.env,然后运行RUN . ./setting.env & . ./setting & ["/bin/bash", "-c", "source ~/.setting.env"],也没有起作用...

非常感谢你的帮助!

编辑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

编辑2]
我尝试了以下方法:

  • RUN /bin/bash -c ". setting.env" / "source setting.env":没有这个文件或目录
英文:

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

答案1

得分: 1

似乎您的镜像中没有包含.env文件。

在将.env文件复制到镜像中后,尝试执行source .env命令。

英文:

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

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

huangapple
  • 本文由 发表于 2022年2月27日 18:41:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/71284065.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定