[英]Docker can't see file created it by Laravel
I hosted Docker on Linux machine, Docker run Laravel project我在 Linux 机器上托管 Docker,Docker 运行 Laravel 项目
I need to store file in var/log
, I will check if var/log
contain logBackups
folder or not, I will create logBackups
folder if it not exists, then I store file inside the logBackups
folder.我需要将文件存储在
var/log
,我将检查var/log
包含logBackups
文件夹,如果它不存在,我将创建logBackups
文件夹,然后将文件存储在logBackups
文件夹中。 Final path will be var/log/logBackups/myfile.zip
最终路径将是
var/log/logBackups/myfile.zip
From the code I see the files inside logBackups
folder, but I can't see the files from Docker itself, I go to var/log
then write ls
to list the files but the folder not exists, I can't find the files.从代码中我看到了
logBackups
文件夹中的文件,但我看不到来自 Docker 本身的文件,我转到var/log
然后写ls
列出文件但文件夹不存在,我找不到文件。
If I search using find -iname myFile*.zip
in the root folder of hosted machine I will find the files under ./var/lib/docker/aufs/diff/6ce08dbaede64ed42b8e44c0bd9ec60ee6c5843a8c4ecc977aaacb4af7ffddee/var/log/logBackups/myfile.zip
and under ./var/lib/docker/aufs/mnt/6ce08dbaede64ed42b8e44c0bd9ec60ee6c5843a8c4ecc977aaacb4af7ffddee/var/log/logBackups/myfile.zip
如果我在托管机器的根文件夹中使用
find -iname myFile*.zip
进行搜索,我将在./var/lib/docker/aufs/diff/6ce08dbaede64ed42b8e44c0bd9ec60ee6c5843a8c4ecc977aaacb4af7ffddee/var/log/logBackups/myfile.zip
下找到文件./var/lib/docker/aufs/mnt/6ce08dbaede64ed42b8e44c0bd9ec60ee6c5843a8c4ecc977aaacb4af7ffddee/var/log/logBackups/myfile.zip
It seems the Laravel project code use session when store data under /var/log
似乎 Laravel 项目代码在
/var/log
下存储数据时使用会话
How can I find my files from Docker itself and force laravel project to use same folder Docker see?如何从 Docker 本身找到我的文件并强制 Laravel 项目使用 Docker 看到的相同文件夹?
Command used to run the project is docker-compose -p projectname up -d
用于运行项目的命令是
docker-compose -p projectname up -d
Dockerfile文件
FROM php:7.1-fpm
RUN apt-get update && apt-get install -y sendmail libmcrypt-dev libpng-dev git-all zlib1g-dev \
&& docker-php-ext-install mcrypt zip pdo_mysql opcache
#Speed PHP
RUN echo "file_uploads = On\n" \
"memory_limit = 1024M\n" \
"upload_max_filesize = 50M\n" \
"post_max_size = 50M\n" \
"max_execution_time = 600\n" \
> /usr/local/etc/php/conf.d/uploads.ini
ADD dockerscriptetchosts.sh /home/dockerscriptetchosts.sh
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN mv composer.phar /usr/local/bin/composer
WORKDIR /var/www
ADD . /var/www
RUN chown -R www-data:www-data /var/www
RUN chown -R www-data:www-data /var/log
Docker-compose yml File Docker-compose yml 文件
version: '2'
services:
web:
build:
context: ./
dockerfile: web.docker
volumes:
- ./:/var/www
ports:
- "9080:80"
links:
- app
app:
build:
context: ./
dockerfile: app.docker
volumes:
- ./:/var/www
- /var/log:/var/www/shared_log
environment:
- "APP_ENV=local"
If you want to directly read content produced by the container in the host system, you need to use a bind-mounted volume to mount a host directory into the container.如果要直接读取宿主机系统中容器产生的内容,则需要使用绑定挂载卷将宿主机目录挂载到容器中。 You should never directly access content in
/var/lib/docker
: it's a complex installation-specific format, and if you get it wrong you can corrupt the filesystem in your container or across all of Docker.你永远不应该直接访问
/var/lib/docker
:它是一种复杂的特定于安装的格式,如果你弄错了,你可能会破坏容器中或整个 Docker 中的文件系统。
The docker-compose.yml
file you show mounts the host's /var/log
directory on to a subdirectory of the application directory;您显示
docker-compose.yml
文件将主机的/var/log
目录挂载到应用程序目录的子目录中; this is a little unusual and probably isn't what you want.这有点不寻常,可能不是您想要的。 You want a
volumes:
declaration more like你想要一个
volumes:
声明更像是
volumes:
- ./webLog:/var/log
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.