Skip to content

Conversation

@dinhngocdung
Copy link

Description
This PR updates the /etc/hosts modification logic to ensure compatibility when EasyEngine is running inside a Docker container (Containerized CLI).

The Problem
Currently, EasyEngine uses Filesystem::dumpFile() (or similar atomic-write logic) which attempts to create a temporary file and rename it to /etc/hosts. In Docker environments where /etc/hosts is bind-mounted from the host machine, this operation fails with "Device or resource busy" because Docker does not allow changing the Inode of mounted system files.

The Solution
The logic has been updated to use direct stream writing via file_put_contents() with LOCK_EX.

Inode Preservation: By writing directly to the existing file, we preserve the Inode, allowing Docker to sync changes seamlessly between the container and the host.

Backwards Compatibility: This change is completely transparent to users running EasyEngine natively on Linux/macOS.

Robustness: Switched to preg_quote() for safer regex handling of site URLs.

Reference Case
This improvement is based on successful implementation in a containerized version of EasyEngine available here: dinhngocdung/easyengine. This image allows users to run EasyEngine as a standalone tool without native installation, and this PR upstreaming ensures the core logic supports this modern deployment method.

Changes
Modified remove_etc_hosts_entry() to use file_put_contents.

Improved regex patterns to be more resilient and documented in English.

Added explicit exception handling for better debugging in container environments.

@dinhngocdung dinhngocdung force-pushed the develop branch 9 times, most recently from 61956ff to 58c42a5 Compare January 12, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant