How do I add a package to an already existing image?

ぐ巨炮叔叔 提交于 2019-12-24 10:52:34

问题


I have a RoR app that uses imagemagick specified in the Gemfile. I am using Docker's official rails image to build my image with the following Dockerfile:

FROM rails:onbuild
RUN apt-get install imagemagick

and get the following error:

Cant install RMagick 2.13.2. Cant find Magick-config in /usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Now, that's probably because the imagemagic package is missing on the OS, even though I specified it in my Dockerfile. So I guess the bundle install command is issued before my RUN apt-get command is issued.
My question - using this base image, is there a way to ensure imagemagic is installed prior to bundling?
Do I need to fork and change the base image Dockerfile to achieve that?


回答1:


you are right, the ONBUILD instructions from the rails:onbuild image will be executed just after the FROM instruction of your Dockerfile.

What I suggest is to change your Dockerfile as follow:

FROM ruby:2.2.0
RUN apt-get install imagemagick

# throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y mysql-client postgresql-client sqlite3 --no-install-recommends && rm -rf /var/lib/apt/lists/*


COPY Gemfile /usr/src/app/
COPY Gemfile.lock /usr/src/app/
RUN bundle install

COPY . /usr/src/app

EXPOSE 3000
CMD ["rails", "server"]

which I made based on the rails:onbuild Dockerfile moving down the ONBUILD instructions and removing the ONBUILD flavor.




回答2:


Most packages clean out the cache to save on size. Try this:

apt-get update && apt-get install imagemagick

Or spool up a copy of the container and look for yourself

docker run -it --remove <mycontainernameorid> /bin/bash

The --remove will ensure that the container is removed after you exit the shell. Once in the shell look for the package binary (or dpkg --list)



来源:https://stackoverflow.com/questions/28027108/how-do-i-add-a-package-to-an-already-existing-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!