Dockerfile里执行RUN chown 不起作用?

Dockerfile如下:主要是安装solr,并且安装分词器,不想手动配置分词器

FROM solr:8.6.2
MAINTAINER zhenhunfan <564090302@qq.com>

# 创建 Core
USER root     #因为下面要创建目录,没有权限,因此用root用户
WORKDIR /var/solr/data
RUN mkdir ik_core
WORKDIR /var/solr/data/ik_core
RUN echo 'name=ik_core' > core.properties
RUN mkdir data
COPY data /var/solr/data/ik_core/data
RUN mkdir conf
COPY conf /var/solr/data/ik_core/conf

# 安装中文分词
WORKDIR /opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF/lib/
ADD ik-analyzer-8.3.0.jar .
ADD ik-analyzer-solr7-7.x.jar .
ADD solr-dataimporthandler-8.4.0.jar .
ADD solr-dataimporthandler-extras-8.4.0.jar .

WORKDIR /opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF
RUN mkdir classes
WORKDIR /opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF/classes
ADD ext.dic .
ADD stopword.dic .
ADD IKAnalyzer.cfg.xml .

RUN cp /opt/solr-8.6.2/contrib/analysis-extras/lucene-libs/lucene-analyzers-smartcn-8.6.2.jar /opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF/lib/

# 增加分词配置
COPY managed-schema /var/solr/data/ik_core/conf
COPY solrconfig.xml /var/solr/data/ik_core/conf
COPY core.properties /var/solr/data/ik_core
chown -R solr:solr /var/solr/data/ik_core/
USER solr
WORKDIR /opt/solr-8.6.2

docker-compose.yml如下:

version: '3.1'
services:
  solr:
    build: ikanalyzer
    restart: always
    container_name: solr
    ports:
      - 8983:8983
    volumes:
      - ./solrdata:/opt/solrdata

但是跑起来后,发现RUN chown -R solr:solr /var/solr/data/ik_core 不起作用,所有者还是root,不知道该怎么办了

解决方法:先把ik_core文件夹组织好,然后通过下面一句话copy进去

COPY --chown=solr:solr ik_core /var/solr/data/ik_core

完整的Dockerfile如下:

FROM solr:8.6.2
MAINTAINER zhenhunfan <564090302@qq.com>

# 创建 Core
USER root
WORKDIR /var/solr/data
RUN mkdir ik_core
COPY --chown=solr:solr ik_core /var/solr/data/ik_core

# 安装中文分词
WORKDIR /opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF/lib/
ADD ik-analyzer-8.3.0.jar .
ADD ik-analyzer-solr7-7.x.jar .
ADD solr-dataimporthandler-8.4.0.jar .
ADD solr-dataimporthandler-extras-8.4.0.jar .

WORKDIR /opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF
RUN mkdir classes
WORKDIR /opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF/classes
ADD ext.dic .
ADD stopword.dic .
ADD IKAnalyzer.cfg.xml .

RUN cp /opt/solr-8.6.2/contrib/analysis-extras/lucene-libs/lucene-analyzers-smartcn-8.6.2.jar /opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF/lib/


USER solr
WORKDIR /opt/solr-8.6.2
posted @ 2020-09-25 17:27  镇魂帆-张  阅读(2125)  评论(0编辑  收藏  举报