├── Dockerfile └── README.md /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7-alpine 2 | 3 | RUN docker-php-ext-install opcache 4 | 5 | RUN mkdir /srv 6 | RUN mkdir /opcache 7 | 8 | RUN echo 'opcache.enable=1' >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini \ 9 | && echo 'opcache.enable_cli=1' >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini \ 10 | && echo 'opcache.validate_timestamps=0' >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini \ 11 | && echo 'opcache.file_cache="/opcache"' >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini \ 12 | && echo 'opcache.file_update_protection=0' >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini 13 | 14 | RUN curl -o /srv/index.php https://gist.githubusercontent.com/jderusse/81050a514f2136efabab5ebd520bc598/raw/e7a89c09764088830c2cce117f2f0054927425da/gistfile1.txt \ 15 | && find -L /srv -name '*.php' -exec php -l {} \; -exec sh -c "echo > {}" \; 16 | 17 | CMD php /srv/index.php 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Docker-magic 2 | ============ 3 | 4 | This docker image is a POC to provide a php image WITHOUT sources 5 | 6 | Proof 7 | ----- 8 | 9 | ``` 10 | $ docker run jderusse/magic php /srv/index.php 11 | Hello World 12 | 13 | $ docker run jderusse/magic cat /srv/index.php 14 | 15 | $ docker run jderusse/magic ls -al /srv/index.php 16 | -rw-r--r-- 1 root root 1 May 25 21:57 /srv/index.php 17 | ``` 18 | 19 | > `1` is the size of the file in bytes. 20 | 21 | 22 | The original source code is available here : https://gist.githubusercontent.com/jderusse/81050a514f2136efabab5ebd520bc598 23 | 24 | How does it work ? 25 | ------------------ 26 | 27 | The original source code is downloaded then compiled by the php engine with a 28 | simple `php -l`. 29 | The compiled result is stored in the opcache files. 30 | 31 | Thanks to the directive `validate_timestamps=0` the original files are not 32 | used anymore. You can empty thoses file, the application still works because 33 | the engine will always use the opcached files. 34 | --------------------------------------------------------------------------------