如何使用GOLang官方图片将不受欢迎的包导入Docker?

时间:2016-08-20 21:40:20

标签: go docker go-imagick

我已经将这个问题作为一个问题发布在imagick git存储库上,但它的用户群非常小,所以我希望能从这里获得一些帮助。我已经尝试了几天,使用官方的goLang dockerfile将https://github.com/gographics/imagick导入Docker,用于我正在进行的项目,但一直没有成功。由于这个软件包不受欢迎,因此运行apt-get不会起作用。我(犹豫地)试图将文件添加到容器中,但这并不起作用。这是我构建的DockerFile及其产生的错误: === DOCKERFILE ===

# 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 ===

这允许我构建docker容器,但是当我尝试运行它时,我在运动学日志中出现以下错误:

=== DOCKER ERROR ===

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 DOCKER ERROR ===

1 个答案:

答案 0 :(得分: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

请务必将-y添加到apt-get install,因为docker build是非互动的。