简体   繁体   中英

Docker can't see file created it by Laravel

I hosted Docker on Linux machine, Docker run Laravel project

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. Final path will be 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.

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

It seems the Laravel project code use session when store data under /var/log

How can I find my files from Docker itself and force laravel project to use same folder Docker see?

Command used to run the project is 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

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.

The docker-compose.yml file you show mounts the host's /var/log directory on to a subdirectory of the application directory; this is a little unusual and probably isn't what you want. You want a volumes: declaration more like

volumes:
  - ./webLog:/var/log

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM