我正在尝试为SOLR扩展Docker容器。我只想安装vim到它。但是,当我运行docker build时,它抱怨我不是root。
vim
这是我要扩展的DockerFile:https : //github.com/makuk66/docker- solr/blob/master/5.3/Dockerfile
我的构建文件是这样的:
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复制原始构建文件?
在Dockerfile#L24中,用户已切换到solr。因此,如果您使用将该图像用作基本图像FROM,Dockerfile则用户自己的所有命令都将由用户运行solr
solr
FROM
Dockerfile
您可以通过从头开始构建Dockerfile来修复它。
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选项将更加灵活。
-v
COPY home/ocscommerce /etc/solr/home
替换为docker run命令-v home/ocscommerce:/etc/solr/home
docker run
-v home/ocscommerce:/etc/solr/home