如何将包添加到已存在的图像? [英] How do I add a package to an already existing image?
问题描述
FROM rails:onbuild
运行apt-get install imagemagick
并收到以下错误:
无法安装RMagick 2.13.2。不能在/ usr / local / bundle / bin中找到Magick-config:/ usr / local / sbin:/ usr / local / bin:/ usr / sbin:/ usr / bin:/ sbin:/ bin
现在,这可能是因为在操作系统上缺少imagemagic软件包,即使我在Docker文件中指定了它。所以我想在运行apt-get
命令发出之前,我已经发出了 bundle install
命令。
我的问题 - 使用这个基本映像,是否有一种方法来确保在捆绑之前安装imagemagic?
我需要fork和更改基本的Dockerfile才能实现吗?
你是对的, ONBUILD
来自 rails:onbuild 图像将在 FROM
您的Dockerfile指令。
我建议更改Dockerfile如下: p>
FROM ruby:2.2.0
运行apt-get install imagemagick
#throw errors if G emfile已经修改,因为Gemfile.lock
RUN bundle config --global frozen 1
RUN mkdir -p / usr / src / app
WORKDIR / usr / src / app
运行apt-get update&& apt-get install -y nodejs --no-install-recommendations&& rm -rf / var / lib / apt / lists / *
RUN apt-get update&& apt-get install -y mysql-client postgresql-client sqlite3 --no-install-recommendations&& rm -rf / var / lib / apt / lists / *
COPY Gemfile / usr / src / app /
COPY Gemfile.lock / usr / src / app /
运行捆绑安装
COPY。 / usr / src / app
EXPOSE 3000
CMD [rails,server]
我根据 rails: onbuild Dockerfile 向下移动 ONBUILD
说明,并删除 ONBUILD
flavor。
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?
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.
这篇关于如何将包添加到已存在的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!