Set up Magento manually from a custom Git branch in Docker
Learn how to manually set up a project in Docker while selecting a custom source branch and managing dependencies.
Lesson Content
To manually install Magento with docker-magento, start by creating a project directory and downloading the Docker Compose template. This process produces the same environment as the one-line setup script, while also allowing you to customize the Magento source, such as checking out a specific Git branch.
Create a project directory under your Sites directory and move into it:
mkdir -p ~/Sites/2.4-develop
cd ~/Sites/2.4-developDownload the Docker Compose template from the docker-magento repository:
curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bashThe project now contains the Docker Compose YAML files and helper scripts used throughout the installation.
Start the Docker containers in the background using only the docker-compose.yml file:
docker-compose -f docker-compose.yml up -dThe -d flag keeps the containers running without occupying the current shell.
Magento requires Composer authentication keys to download its packages. Copy the keys from your host machine into the container:
bin/setup-composer-authNow clone the Magento repository from GitHub using the bin/cli helper:
bin/cli git clone [email protected]:magento/magento2.git .The command runs Git inside the Docker container instead of on the host. This avoids downloading the repository on the host and then copying all of its files into the container.
The Git clone uses SSH authentication, so your host machine needs an SSH key configured for GitHub. The Docker Compose configuration mounts the host SSH key into the container, allowing Git to authenticate through the SSH protocol.
Check out the branch you want to use. This example uses the 2.4-develop branch:
bin/cli git checkout 2.4-developYou can use bin/cli to run any command inside the Docker container. For example, verify the active Git branch:
bin/cli git branchInstall Magento's Composer dependencies with the helper script:
bin/composer installAlways use the bin/composer prefix. Running composer install directly uses the Composer binary on your host machine instead of the version inside the Docker container.
With the Magento source and dependencies in place, run the setup script. Pass the local hostname you want Magento to use. The .test top-level domain is intended for local development:
bin/setup m24develop.testThe setup script restarts the containers and runs the Magento installation. It also copies selected files from the container back to the host, deploys static content, reindexes Magento, and generates an SSL certificate.
During setup, the script asks for your host machine password. It uses that password to add the local hostname to /etc/hosts and to install the generated certificate authority in the host system's trust store.
After the certificate is trusted, the containers restart to apply the changes. The script then installs additional development tools, clears the cache, installs Magento cron, and enables developer mode.
When setup finishes successfully, open https://m24develop.test in your browser. After the initial loading period, the default Magento Luma home page appears, confirming that Magento is running from the custom 2.4-develop Git branch.
Join the discussion!
Comments
Want to comment on this lesson?
Log in to leave comments.