[英]How to import an unpopular package to Docker using the GOLang official image?
I've posted this question already as an issue on the imagick git repository, but it has a very small user-base, so I'm hoping to get some help from here. 我已经将这个问题作为问题发布在imagick git存储库上,但是它的用户群很小,所以我希望从这里获得一些帮助。 I've been trying for a few days now to import https://github.com/gographics/imagick to Docker using the official goLang dockerfile for a project I'm working on, but have been unsuccessful. 我已经尝试了几天,使用我正在开发的项目的官方goLang dockerfile将https://github.com/gographics/imagick导入Docker,但未成功。 Since this package isn't popular, running apt-get won't work. 由于此软件包不受欢迎,因此无法运行apt-get。 I've (hesitantly) tried to just add the files to the container, but that didn't work. 我(犹豫地)试图将文件添加到容器中,但这没有用。 Here's the DockerFile I've built and the error it produces: ===DOCKERFILE=== 这是我构建的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=== ===结束文档文件===
This allows me to build the docker container, but when I try to run it, I get the following error in the logs of kinematic: 这使我可以构建docker容器,但是当我尝试运行它时,在运动学日志中会出现以下错误:
===DOCKER ERROR=== === DOCKER错误===
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=== ===结束文档错误===
Most base images have package lists removed to avoid to reduce image size. 大多数基本映像都删除了软件包列表,以避免减小映像大小。 Thus, in order to install something with apt-get
, you first need to update the package lists and then install whatever package you wish. 因此,为了使用apt-get
安装某些东西,您首先需要更新软件包列表,然后再安装所需的任何软件包。 Then, after installing the package, remove all side-effects of running apt to avoid polluting the image with unneeded files (all that necessarily as a single RUN
command). 然后,在安装软件包之后,消除运行apt的所有副作用,以避免不必要的文件污染映像(所有这些都必须作为单个RUN
命令执行)。
The following Dockerfile should do the trick: 以下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
Remember to add -y
to apt-get install
, because docker build
is non-interactive. 切记在apt-get install
添加-y
,因为docker build
是非交互式的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.