Changes sync with container does not always work perfectly
Hello,
I am not sure why https://github.com/markshust/docker-magento/issues/1313 was closed, because it is an issue and does happen quite often to me, too.
It appears to be syncing, but sometimes the file content gets cut off, which causes an error when refreshing.
I often see this issue, and the error looks like: ParseError: syntax error, unexpected end of file.
It probably does not happen on small projects, but it does happen regularly on big projects.
The only solution I have found is running bin/copytocontainer --all or a specific folder you are working on (usually app/code or app/design).
For example, if I am working on the same app/code file, it will sync it 2-3 times in a row, but the 4th time will most likely lead to the error message I have specified earlier.
Any suggestions?
Thank you!
Hi @NikitaNoaks! I'm Dosu and I’m helping the docker-magento team.
File sync issues like partial file content and "unexpected end of file" errors are a known challenge with docker-magento, especially on large projects or certain environments (like Apple M1 and Docker Desktop). This happens because Docker's built-in volume mounts can sometimes fail to sync files completely, particularly under heavy I/O or with many files, leading to incomplete writes that PHP then tries to parse, resulting in syntax errors[^1][^2].
The recommended workaround is to use bin/copytocontainer to manually copy files or folders from the host to the container, which forces a complete copy and resets permissions[^3]. Many users in the community have reported that this is the only reliable way to ensure changes are reflected, especially when automatic sync fails[^4].
To minimize issues: keep the list of synced directories as small as possible, follow the setup procedure for existing projects, and ensure your compose.dev.yaml is configured correctly[^1][^5]. For larger projects or persistent problems, consider using your IDE's SFTP/SSH sync features (as described in the README) or exploring third-party sync tools, though the maintainer notes that alternatives like Mutagen and docker-sync have their own reliability tradeoffs[^6].
If you haven't already, try disabling the Magento full page cache during development to make sure changes appear after syncing[^5]. Unfortunately, there is no custom sync daemon in docker-magento, so these manual steps are currently the best way to work around Docker's sync limitations.
[^1]: compose.dev.yaml sync config [^2]: Discussion of sync reliability [^3]: bin/copytocontainer script details [^4]: User reports on sync issues [^5]: README: Known issues and setup [^6]: Maintainer's comments on sync alternatives
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
@NikitaNoaks I also sometimes encounter this error, but it seems to be only for composer.json file if I make any changes manually
bin/restart helps me to fix it
Dosu is very wrong here -- this is not a known issue, nor have I ever experienced it. bin/copytocontainer and bin/copyfromcontainer are simple helper scripts that allow you to hard-copy files over, but they should never be needed in a normal dev workflow.
I'm wondering if this is an issue with Docker Desktop. I've been using Orbstack and have had no issues (https://orbstack.dev/). I've had numerous problems in the past running Docker Desktop on projects with larger filesystems.
Updated answer: After too many attempts and failed solutions, it came down to moving the mounted volumes from the docker-compose.dev.yml to under the app service inside the docker-cmopose.yml like this, ie
app:
image: markoshust/magento-nginx:1.24-0
ports:
- "443:8443"
- "80:8000"
links:
- db
- phpfpm
depends_on:
- phpfpm
volumes: &appvolumes
- ~/.composer:/var/www/.composer:cached
- ~/.ssh/id_rsa:/var/www/.ssh/id_rsa:cached
- ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached
- appdata:/var/www/html
- sockdata:/sock
- ssldata:/etc/nginx/certs
- ./src/app/code:/var/www/html/app/code:cached
- ./src/app/design:/var/www/html/app/design:cached
- ./src/app/etc:/var/www/html/app/etc:cached
- ./src/composer.json:/var/www/html/composer.json:cached
- ./src/composer.lock:/var/www/html/composer.lock:cached
- ./src/nginx.conf:/var/www/html/nginx.conf:cached
- ./src/auth.json:/var/www/html/auth.json:cached
- ./src/package.json.sample:/var/www/html/package.json:cached
PS: Save, and bin/restart, try modifying and saving the file in your PHPSTORM again, check the file in the container, changes will flow in.
I'm experience the exact same issue. Perhaps since I upgraded my MacBook Pro to Tahoe? Or when I updated docker-magento tag