2016-08-20 57 views
0

我已经发布这个问题已经作为imagi git存储库上的问题,但它有一个非常小的用户基础,所以我希望从这里得到一些帮助。我一直在试着用几天的时间将https://github.com/gographics/imagick导入Docker,使用正式的goLang dockerfile作为我正在开发的一个项目,但一直没有成功。由于这个软件包不太流行,运行apt-get将不起作用。我(犹豫)试图将文件添加到容器中,但没有奏效。以下是我已经建立了DockerFile和错误它产生: === DOCKERFILE ===如何使用GOLang官方图片将不受欢迎的包导入Docker?

# 1) Use the official go docker image built on debian. 
FROM golang:latest 

# 2) ENV VARS 
ENV GOPATH $HOME/<PROJECT> 
ENV PATH $HOME/<PROJECT>/bin:$PATH 

# 3) Grab the source code and add it to the workspace. 
ADD . /<GO>/src/<PROJECT> 
ADD . /<GO>/gopkg.in 
# Trying to add the files manually... Doesn't help. 
ADD . /opt/local/share/doc/ImageMagick-6 


# 4) Install revel and the revel CLI. 
#(The commented out code is from previous attempts) 
#RUN pkg-config --cflags --libs MagickWand 
#RUN go get gopkg.in/gographics/imagick.v2/imagick 
RUN go get github.com/revel/revel 
RUN go get github.com/revel/cmd/revel 

# 5) Does not work... Can't find the package. 
#RUN apt-get install libmagickwand-dev 

# 6) Get godeps from main repo 
RUN go get github.com/tools/godep 

# 7) Restore godep dependencies 
WORKDIR /<GO>/src/<PROJECT> 
RUN godep restore 

# 8) Install Imagick 
#RUN go build -tags no_pkgconfig gopkg.in/gographics/imagick.v2/imagick 

# 9) Use the revel CLI to start up our application. 
ENTRYPOINT revel run <PROJECT> dev 9000 

# 10) Open up the port where the app is running. 
EXPOSE 9000 

=== END DOCKERFILE ===

这让我建立泊坞窗容器,但当我尝试运行它,我得到了运动的记录以下错误:

===泊坞窗错误===

ERROR 2016/08/20 21:15:10 build.go:108: # pkg-config --cflags MagickWand MagickCore MagickWand MagickCore 
pkg-config: exec: "pkg-config": executable file not found in $PATH 
2016-08-20T21:15:10.081426584Z 
ERROR 2016/08/20 21:15:10 build.go:308: Failed to parse build errors: 
#pkg-config --cflags MagickWand MagickCore MagickWand MagickCore 
pkg-config: exec: "pkg-config": executable file not found in $PATH 
2016-08-20T21:15:10.082140143Z 

=== END泊坞窗ERROR ===

回答

1

大多数基础图像都删除了软件包列表以避免减少图像大小。因此,为了安装apt-get,首先需要更新软件包列表,然后安装任何你想要的软件包。然后,在安装软件包之后,删除运行apt的所有副作用,以避免使用不需要的文件污染映像(所有这些都必须作为单个RUN命令)。

以下Dockerfile应该做的伎俩:

FROM golang:latest 

RUN apt-get update \ # update package lists 
&& apt-get install -y libmagickwand-dev \ # install the package 
&& apt-get clean \ # clean package cache 
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # remove everything else 

RUN go get gopkg.in/gographics/imagick.v2/imagick 

记住添加-yapt-get install,因为docker build是非交互。

+0

今天早些时候我实际上已经想到了这一点(尽管有一些试验和错误),但是感谢回复。这对任何寻求帮助的人都有用。 – Anarch