douwen8118 2016-08-20 21:40
浏览 55
已采纳

如何使用GOLang官方映像将不受欢迎的软件包导入Docker?

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. 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. Since this package isn't popular, running apt-get won't work. 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===

# 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 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条回答 默认 最新

  • duanfan8699 2016-08-21 11:04
    关注

    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. 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).

    The following Dockerfile should do the trick:

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?