如何将新软件包安装到非根Docker容器中? [英] How to install new packages into non-root Docker Container?
问题描述
我正在尝试为SOLR扩展Docker容器。我只想在其中安装 vim
。但是当我运行docker build时,它抱怨我不是root用户。
I'm trying to extend a docker container for SOLR. I just want to install vim
into it. But when I run the docker build it complains that I'm not root.
这是我要扩展的DockerFile:
https://github.com/makuk66/docker-solr/blob/master/5.3/Dockerfile
This is the DockerFile that I'm extending: https://github.com/makuk66/docker-solr/blob/master/5.3/Dockerfile
我的构建文件是这样的:
And my build file is this:
FROM makuk66/docker-solr
MAINTAINER OCSCommerce Team <support@ocscommerce.com>
RUN apt-get update
RUN apt-get --assume-yes install vim
COPY home/ocscommerce /etc/solr/home
然后输出以下内容:
192.168.99.100
localhost:solr$ docker build -t ocscommerce/solr .
Sending build context to Docker daemon 39.66 MB
Step 0 : FROM makuk66/docker-solr
---> 92be2fe79f15
Step 1 : MAINTAINER OCSCommerce Team <support@ocscommerce.com>
---> Using cache
---> a3ac70e40324
Step 2 : RUN apt-get update
---> Running in c865716a2694
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
是否可以将软件包安装到此容器中?还是我需要从makuk66复制原始构建文件?
Is there any way to install a package into this container? Or would I need to copy the original build file from makuk66?
推荐答案
在 Dockerfile#L24 ,用户已切换到 solr
。因此,如果将映像用作 FROM
的基本映像,则您自己的 Dockerfile
中的所有命令都由用户 solr
In the Dockerfile#L24, the user has been switched to solr
. So if you use the image as base image with FROM
, all commands in your own Dockerfile
are running by the user solr
您可以通过从头开始构建Dockerfile来修复它。
You can fix it by building the Dockerfile from beginning.
FROM java:openjdk-8-jre
MAINTAINER Martijn Koster "mak-docker@greenhills.co.uk"
ENV SOLR_VERSION 5.3.0
ENV SOLR solr-$SOLR_VERSION
ENV SOLR_USER solr
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get -y install lsof && \
groupadd -r $SOLR_USER && \
useradd -r -g $SOLR_USER $SOLR_USER && \
mkdir -p /opt && \
wget -nv --output-document=/opt/$SOLR.tgz http://www.us.apache.org/dist/lucene/solr/$SOLR_VERSION/$SOLR.tgz && \
tar -C /opt --extract --file /opt/$SOLR.tgz && \
rm /opt/$SOLR.tgz && \
ln -s /opt/$SOLR /opt/solr && \
mkdir -p /opt/solr/server/solr/lib && \
chown -R $SOLR_USER:$SOLR_USER /opt/solr /opt/$SOLR
RUN apt-get --assume-yes install vim
EXPOSE 8983
WORKDIR /opt/solr
USER $SOLR_USER
CMD ["/bin/bash", "-c", "/opt/solr/bin/solr -f"]
第二,在构建时不要将代码复制到容器中,请使用 -v
选项将更加灵活。
Second, don't copy the codes to container when building, use -v
option will be more flexible.
COPY home/ocscommerce /etc/solr/home
替换为 docker run
命令 -v home / ocscommerce:/ etc / solr / home
这篇关于如何将新软件包安装到非根Docker容器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!