如何创建文件和挂载文件系统为只读?

时间:2018-02-19 19:06:49

标签: docker docker-compose dockerfile

我有以下Dockerfile(我删除了不相关的内容):

FROM centos:centos6   
ENV TERM=xterm   
ARG INSTALL_WKHTMLTOPDF=no
ARG WKHTMLTOPDF_VERSION=latest
ARG INSTALL_PDFTK=no
ARG PDFTK_VERSION=latest
ARG PHP_VERSION=default
... 
COPY container-files /
...
EXPOSE 80 9001
WORKDIR /var/www/html
ENTRYPOINT bash -C '/entrypoint.sh';'bash'

entrypoint.sh如下:

#!/bin/bash
set -e

if [ "$UID" == 0 ]; then
    uid=1000;
else
    uid=${UID};
fi

if [ -z "${GID}" ]; then
    gid=1000;
else
    gid=${GID};
fi

echo "UID: $uid"
echo "GID: $gid"

touch /var/log/xdebug.log
chown apache:root /var/log/xdebug.log   
rm -f /var/run/apache2/apache2.pid   
exec httpd -DFOREGROUND "$@"

最后是docker-compose.yml文件:

version: '3.4'
services:
    erx:
      image: arx_dev
      ports:
        - "80:80"
      environment:
        VHOST_DOCUMENT_ROOT: /var/www/html
      volumes:
        - ./server_logs:/var/log/:ro

构建映像并尝试docker-compose up -d后,它无法启动,因为touch无法在RO文件系统中创建文件。

PS F:\Development\docker\rx> docker logs rx_erx_1
UID: 1000
GID: 1000
touch: cannot touch `/var/log/xdebug.log': Read-only file system
PS F:\Development\docker\rx>

如何创建文件,然后将/var/log挂载为只读?我想直接从主机检查一些日志,避免bash进入容器。有什么想法吗?

0 个答案:

没有答案