【问题标题】:How to import an unpopular package to Docker using the GOLang official image?如何使用GOLang官方镜像将冷门包导入Docker?
【发布时间】:2016-08-20 21:40:20
【问题描述】:

我已经将这个问题作为一个问题发布在 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 容器,但是当我尝试运行它时,我在 kinematic 的日志中收到以下错误:

===码头错误===

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 

===结束码头工人错误===

【问题讨论】:

    标签: go docker go-imagick


    【解决方案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 是非交互式的。

    【讨论】:

    • 我实际上在今天早些时候发现了这一点(尽管经过了一些试验和错误),但感谢您的回复。这确实对任何寻求帮助的人有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-21
    • 2019-08-26
    • 2016-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    相关资源
    最近更新 更多