Question

I'm using the Docker DevBox (Beta) from Magento for development. Unfortunately, after developing a while, it seems that the container caches everything. Sometimes it helps when I restart Docker. In the worst case, I have to initiate the Docker container again (via m2devbox-init.sh).

Developing environment details:

  • macOS Sierra (10.12.3)
  • Docker Community Edition (17.03.1-ce-mac5 (16048), channel stable)
  • Current DevBox with Magento v. 2.1.5 (not modified)

I had the same problem with two different Magento 2 projects now, so I assume it does not depend on third party Magento modules.

In the Docker container, I can't restart php-fpm by typing "service php-fpm restart" because there seems to be no service with this name.

# sudo service --status-all              
 [ + ]  apache2
 [ - ]  bootlogs
 [ - ]  bootmisc.sh
 [ - ]  checkfs.sh
 [ - ]  checkroot-bootclean.sh
 [ - ]  checkroot.sh
 [ + ]  cron
 [ - ]  exim4
 [ - ]  hostname.sh
 [ ? ]  hwclock.sh
 [ - ]  killprocs
 [ - ]  motd
 [ - ]  mountall-bootclean.sh
 [ - ]  mountall.sh
 [ - ]  mountdevsubfs.sh
 [ - ]  mountkernfs.sh
 [ - ]  mountnfs-bootclean.sh
 [ - ]  mountnfs.sh
 [ - ]  procps
 [ - ]  rc.local
 [ - ]  rmnologin
 [ - ]  rsync
 [ - ]  sendsigs
 [ + ]  ssh
 [ - ]  sudo
 [ - ]  supervisor
 [ + ]  udev
 [ ? ]  udev-finish
 [ - ]  umountfs
 [ - ]  umountnfs.sh
 [ - ]  umountroot
 [ - ]  urandom
 [ - ]  x11-common

But of course, there is php-fpm running (you can see it in the active processes).

I have tried the following steps to flush the cache:

  • run "bin/magento cache:flush"
  • deleted static content files and cache from file system
  • created a php file with "opcache_reset()" in it and run it
  • killed all php-fpm processes
  • flushed the cache in the Magento backend
  • completely disabled the cache with "bin/magento cache:disable"
  • developer mode is turned on, of course

Something in this container is caching my code. It's caching php, JavaScript and phtml-template files. The Docker container is a good tool to work with, but this caching problems take so much time that I have to temporary switch back to XAMPP until, hopefully, someone can help me.

Was it helpful?

Solution

OPCache is causing this problem. You have to create a php file (eg. reset_opcache.php) which is accessible via browser and put the following code inside:

<?php opcache_reset(); ?>

Assuming your project url is 127.0.0.1 and you put the file in the Magento root folder, open http://127.0.0.1/reset_opcache.php in your browser. There will be no output, but your changes will now affect.

You can also call the file from your terminal, but the cgi php uses another (or no) OP Cache. So it won't affect your changes.

If your reset_opcache.php is not accessible via browser (because obviously OP Cache is 'preventing' you from calling the file), try restarting the container, or restarting Docker, or - in the worst case - restarting your machine. As long as you can access the file in the browser.

OTHER TIPS

It's happened here, it issue has happened because I selected to use Redis and Varnish.

But first run this command to clean the OPCache to check:

php -r "opcache_reset();" 

You can disable that, clicking on this option below Show Advanced Options:

Show Advanced Options

So unselect the Redis and Varnish:

Redis and Varnish DevBox Magento 2

When run in your machine, inside of your Docker container execute:

alias mage="php -d memory_limit=-1 -f bin/magento"
mage deploy:mode:set developer
chmod -R 775 pub/static/ var/ pub/media/ &&
rm -rf var/view_preprocessed/ var/cache/ var/page_cache/ var/tmp/ var/generation/ pub/static/frontend/ ;
mage cache:disable &&
mage indexer:reindex &
mage setup:upgrade &&
mage setup:static-content:deploy && 
mage setup:db-data:upgrade &&
mage dev:source-theme:deploy &&
chmod -R 775 pub/static/ pub/media/ var/
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top