[英]vendor/database cannot find package in Docker image
I'm writing a simple app in GO and using postges I have this folder structure我正在用 GO 编写一个简单的应用程序并使用 postges 我有这个文件夹结构
|--- Dockerfile
|--- api.go
|--- vendor/
database/
init.go
and here is my dockerfile这是我的 dockerfile
FROM golang:1.9
ARG app_env
ENV APP_ENV $app_env
COPY . .
WORKDIR /project
RUN go get ./vendor/database
RUN go get ./
RUN go build
CMD if [ ${APP_ENV} = production ]; \
then \
api; \
else \
api; \
fi
EXPOSE 8080
when I working docker-compose up I m getting this error:当我使用 docker-compose up 时,出现此错误:
Error Message错误信息
Step 6/10 : RUN go get ./vendor/database
---> Running in 459740ba584c
can't load package: package ./vendor/database: cannot find package "./vendor/database" in:
/project/vendor/database
Service 'api' failed to build: The command '/bin/sh -c go get ./vendor/database' returned a non-zero code: 1
Where am I going wrong with the project structure?项目结构哪里出了问题?
You are copying the source to default directory of the base image with the command COPY . .
您正在使用命令
COPY . .
将源复制到基本映像的默认目录COPY . .
COPY . .
. . Then you are making
/project
as working directory with WORKDIR /project
.然后,您将
/project
用作WORKDIR /project
工作目录。 So when you run RUN go get ./vendor/database
, the command is actually run in /project/vendor/database
which does not exist.因此,当您运行
RUN go get ./vendor/database
,该命令实际上是在不存在的/project/vendor/database
运行的。 Switch the order of COPY and WORKDIR as follows将 COPY 和 WORKDIR 的顺序切换如下
WORKDIR /project
COPY . .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.