我正在嘗試更改Dockerfile上創建的文件夾persimisions以創建自定義elasticsearch圖像。從dockerfile chowning docker文件夾
我不明白爲什麼一旦圖像被拉出並且elasticsearch工作,文件夾權限保持不變。
我只是想在/usr/share/elasticsearch
下創建一個backup
文件夾。創建好後更改的權限:
COPY ./backup.sh .
RUN ["chmod", "+x", "./backup.sh"]
CMD ["./backup.sh"]
其中backup.sh
文件內容是:
mkdir backup
chown -R elasticsearch:elasticsearch ./backup
backup
文件夾/usr/share/elasticsearch
下創建的,不過,它的權限不變:
#docker exec -it es ls -la /usr/share/elasticsearch
drwxr-xr-x. 1 root root 4096 Jan 16 12:11 .
drwxr-xr-x. 1 root root 4096 Aug 31 17:30 ..
drwxr-xr-x. 2 >>>>root<<<< >>>>root<<<< 4096 Jan 16 12:03 backup <<<<<<<<<<<<<<<<<
-rwxr-xr-x. 1 root root 58 Jan 16 12:02 backup.sh
drwxr-xr-x. 2 root root 4096 Jan 16 12:11 bin
drwxr-xr-x. 3 elasticsearch elasticsearch 4096 Jan 16 12:11 config
drwxr-xr-x. 3 elasticsearch elasticsearch 4096 Jan 16 12:11 data
drwxr-xr-x. 2 root root 4096 Jan 16 12:11 lib
drwxr-xr-x. 2 elasticsearch elasticsearch 4096 Aug 31 17:30 logs
drwxr-xr-x. 5 root root 4096 Jan 16 12:11 modules
drwxr-xr-x. 2 elasticsearch elasticsearch 4096 Aug 29 09:24 plugins
任何想法?
編輯
Dockerfile:
FROM elasticsearch:2.4
COPY ./backup.sh .
RUN ["chmod", "+x", "./backup.sh"]
CMD ["./backup.sh"]
VOLUME /usr/share/elasticsearch/backup
backup.sh:
mkdir backup
chown -R elasticsearch:elasticsearch ./backup
EDIT2
我剛剛拿到了這個想法從official elasticsearch:2.4 dockerfile。我提出的片段:
WORKDIR /usr/share/elasticsearch
RUN set -ex \
&& for path in \
./data \
./logs \
./config \
./config/scripts \
; do \
mkdir -p "$path"; \
chown -R elasticsearch:elasticsearch "$path"; \
done
VOLUME /usr/share/elasticsearch/data
我也試過這樣:
WORKDIR /usr/share/elasticsearch
RUN set -ex \
&& for path in \
./backup \
; do \
mkdir -p "$path"; \
chown -R elasticsearch:elasticsearch "$path"; \
done
VOLUME /usr/share/elasticsearch/backup
然而,backup
被分配到root:root
代替elasticsearch:elasticsearch
:
#docker exec -it es ls -la /usr/share/elasticsearch
drwxr-xr-x. 10 root root 4096 Jan 17 08:02 .
drwxr-xr-x. 51 root root 4096 Aug 31 17:30 ..
drwxr-xr-x. 2 root root 4096 Jan 17 08:06 backup <<<<<<<<<<<<
drwxr-xr-x. 2 root root 4096 Jan 17 08:08 bin
drwxr-xr-x. 3 elasticsearch elasticsearch 4096 Jan 17 08:08 config
drwxr-xr-x. 3 elasticsearch elasticsearch 4096 Jan 17 08:08 data
drwxr-xr-x. 2 root root 4096 Jan 17 08:08 lib
drwxr-xr-x. 2 elasticsearch elasticsearch 4096 Aug 31 17:30 logs
drwxr-xr-x. 5 root root 4096 Jan 17 08:08 modules
drwxr-xr-x. 2 elasticsearch elasticsearch 4096 Aug 29 09:24 plugins
你能否提供一個示例Dockerfile +上下文來重新創建問題? – minamijoyo
我剛剛添加了完整的Dokcerfile和backup.sh文件。 – Jordi