Set up Magento with the automated onelinesetup script in Docker
Learn how to automate Magento project setup in Docker using a configuration script.
Lesson Content
Create a directory for the project, then move into it:
cd ~/Sites
mkdir magento
cd $_Next, open the docker-magento repository at github.com/markshust/docker-magento, scroll to the setup instructions, and copy the automated setup command for a new project.
curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/onelinesetup | bash -s -- magento.test 2.4.3-p1The command accepts the domain where you want to access Magento. It uses magento.test by default, but you can replace it with a domain such as mystore.test. Keeping the .test top-level domain is recommended because it is reserved for local development and avoids conflicts with public domains and local networks.
The command also accepts the Magento version to install. The automated installer generally supports only the most recent version because maintaining different Magento versions and their dependency requirements is difficult. If you need an older version, check the repository history for a commit that supports it.
Paste the setup command into your project directory and execute it. The script downloads any required Docker images, starts the containers, and begins installing Magento.
If Composer authentication is required, create access keys at marketplace.magento.com. After logging in, open your name menu, select My Profile, then open the Marketplace tab and select My Products. Open Access Keys, and select Create a New Access Key if you do not already have one.
Give the key any name you want, such as Magento, and select OK. Magento provides a public key and a private key. Use the public key as the Composer username and the private key as the Composer password when the setup script prompts you.
The setup script uses Composer to download Magento and its dependencies, then runs composer install. After that, the containers restart and Docker Magento’s internal bin/setup helper installs Magento.
The installer copies the generated files from the Docker container back to your host machine, deploys static content, and reindexes Magento. It then asks for your host machine password so it can add the .test domain to the /etc/hosts file. Enter the password for your computer when prompted.
Next, the installer generates an SSL certificate inside the Docker container and creates a certificate authority file. Your operating system asks for permission to update its trusted certificate settings. Enter your host machine password and confirm the update. Without this step, your browser will not trust the generated SSL certificate.
The containers restart again, the cache is flushed, Magento cron is installed, and developer mode is enabled. When the installation finishes, the script displays the domain where you can access Magento.
Open that domain in a browser. You should see Magento’s default Luma homepage, which confirms that the installation completed successfully.
You can also verify the installed Magento version from the project directory:
bin/magento -VIf you run into problems, open a discussion or file an issue in the docker-magento GitHub repository.
Join the discussion!
Comments
Want to comment on this lesson?
Log in to leave comments.