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.

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

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格