-
Is Docker for Free?
Docker CE is allowed to utilize and download. With Basic Docker EE, you get the Docker platform for guaranteed systems, alongside help from Docker Inc.
Your additionalá¹£ access ensured Docker Containers and Docker Plugins from Docker Store.
-
Install Docker
The first step is to download the Docker and install it. Docker is available for all the major operating systems out there, including Mac OS X, Windows, Ubuntu, Debian, CentOS, and more.
The following steps are the same or almost similar, no matter what operating system you are using.
-
Install Composer
Even though there are different approaches to install and manage Magento 2, Composer is a popular way.
Composer will permit you to manage and install packages and will empower you to pursue extra scripts at each update.
Moreover, you may have seen "uninstall" scripts in some Magento developments. These scripts possibly work when the expansion or module is dealt with by Composer.
-
Download Magento 2
Follow the below steps to download and begin with Magento 2 Docker setup.
- First, go to the Magento marketplace and create an account. Once you're in, check for the Access Keys and have that window open as you need these keys further.
- Locate the place where you would like to download and install the file.
- Open up a command-line terminal. Displace the placeholder path with the outright path of where you intend to download/install Magento. Then copy and paste the below code.
cd /path/to/where/you/will/download/magento && \
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition- Now you possess the latest version of Magento 2 downloaded to your device. Promptly the directory where you installed Magento will refer to as /path/to/magento.
- The default value of the PHP memory is 756M; change it to 2048M.
find . -name '.htaccess' -exec sed -i '' s/756M/2048M/g {} + && \
find . -name '.htaccess' -exec sed -i '' s/768M/2048M/g {} + && \
find . -name '.user.ini' -exec sed -i '' s/756M/2048M/g {} + && \
find . -name '.user.ini' -exec sed -i '' s/768M/2048M/g {} +- It's time to pick a domain name for your site and add it to your host's file. You will access the site using this name.
sudo -- sh -c "echo '127.0.0.1 local.domain.com' >> /etc/hosts"
Also Read: How To Reindex In Magento 2 From Command Line And Backend
-
Create a docker-compose.yml file
- On your device, pick a place where you wish to keep your Docker configuration files. This location will be called as /path/to/docker.
- cd /path/to/docker
- Now utilizing the text editor of your choice, open a new text document.
- Please copy the following code and paste it into the new file you opened.
version: '3'
services:
web:
image: webdevops/php-apache-dev:ubuntu-16.04
container_name: web
restart: always
user: application
environment:
- WEB_ALIAS_DOMAIN=local.domain.com
- WEB_DOCUMENT_ROOT=/app/pub
- PHP_DATE_TIMEZONE=EST
- PHP_DISPLAY_ERRORS=1
- PHP_MEMORY_LIMIT=2048M
- PHP_MAX_EXECUTION_TIME=300
- PHP_POST_MAX_SIZE=500M
- PHP_UPLOAD_MAX_FILESIZE=1024M
volumes:
- /path/to/magento:/app:cached
ports:
- "80:80"
- "443:443"
- "32823:22"
links:
- mysql
mysql:
image: mariadb:10
container_name: mysql
restart: always
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=magento
volumes:
- db-data:/var/lib/mysql
phpmyadmin:
container_name: phpmyadmin
restart: always
image: phpmyadmin/phpmyadmin:latest
environment:
- MYSQL_ROOT_PASSWORD=root
- PMA_USER=root
- PMA_PASSWORD=root
ports:
- "8080:80"
links:
- mysql:db
depends_on:
- mysql
volumes:
db-data:
external: false- Put your domain name on the above code and place it at the "environment" you have just created in the above step.
- Now replace the code "/path/to/magento" above with the absolute path where you have downloaded the Magento files earlier. Leave everything exactly the way it is.
- In the end, save this new file as /path/to/docker/docker-compose.yml
-
Now We're Ready to Fire It Up
- Now, check whether your terminal is still open at /path/to/docker. It needs to be available.
- The moment you push, in the first go, Docker will download the images. The process may take a few minutes. In the future spins, the process will complete in less than 10 seconds.
docker-compose up -d --build
- To check whether this is working and you achieved success or not, open your web browser, go to 127.0.0.1:8080 and look for phpMyAdmin. If you can, it was a success.
-
Install Magento 2 For Docker
- Now locate your Docker web container's command line.
docker exec -it web bash
- Go to the web document root.
cd /app
- This action is optional but recommended for better performance: Do deploy the sample data.
php bin/magento sampledata:deploy
- Now, Install Magento 2, and you must replace the values with your details such as first name, last name, email, admin URL, password, and URL. Now copy and paste the command shown below into the Docker terminal. Do not forget to change the placeholder domain with the domain name you created earlier.
php bin/magento setup:install \
--admin-firstname=John \
--admin-lastname=Doe \
--admin-email=johndoe@example.com \
--admin-user=admin \
--admin-password='SomePassword123' \
--base-url=https://local.domain.com \
--base-url-secure=https://local.domain.com \
--backend-frontname=admin \
--db-host=mysql \
--db-name=magento \
--db-user=root \
--db-password=root \
--use-rewrites=1 \
--language=en_US \
--currency=USD \
--timezone=America/New_York \
--use-secure-admin=1 \
--admin-use-security-key=1 \
--session-save=files \
--use-sample-data- Open your internet browser, log in, and visit your site at https://local.domain.com or the domain you picked. For the first time, when you access the site, it may take several minutes for the page to stack. Moreover, on the first occasion, when you visit the URL, the browser will present your page with a security alert because the web container utilizes a self-marked SSL certification. Follow any prompts to include a particular case so you can continue to the nearby site.
- And there you go, running Magento 2 on Docker. Remember, this cycle is effectively repeatable for different undertakings. This process may seem very long but trust us, once it becomes habitual, you will be able to finish the whole process in a minute.
-
Helpful Docker Information & Commands
Since you have your Magento 2 task fully operational on a progression of Docker containers, the following info and commands will be for you to take advantage of it.
-
Docker Info
- Your information base is constant because of an information volume contained in the docker-compose.yml record. This implies when you destroy the virtual machine and turn it back up sometime in the distant future or time, your information base will, in any case, be flawless and all set.
- If you might want to utilize Sequel Pro or different instruments to interface with the information base, it is open at 127.0.0.1:3306. The username is the root, and the secret key is root. The name of the information base is Magento.
- The VM incorporates phpMyAdmin for your benefit. It tends to be gotten to from an internet browser at 127.0.0.1:8080.
-
Docker Commands
- Spin Up
docker-compose up -d --build
- Tear Down
docker-compose down
- Connect to web container CLI
docker exec -it web bash
- Connect to database container CLI
docker exec -it mysql bash
- Spin Up
-
Conclusion:
This blog post has done a deep dive into what is docker and how it works.
We have listed all the commands and information which are essential. Feel free to ask if you have any questions!