Skip to content

Instantly share code, notes, and snippets.

@SamJUK SamJUK/m2docker.sh Secret
Last active Oct 6, 2019

Embed
What would you like to do?
Magento 2 Docker Setup
#!/usr/bin/env bash
#
# After installation, you can start the environment with `docker-compose up -d`
# And then stop all the services with `docker-compose down`
#
echo "**************************************";
echo "* Magento 2 Local Docker Environment *";
echo "**************************************";
echo "* Please enter the configuration *";
echo "* details for this instance. *";
echo "**************************************";
read -p "What domain do you want to use? " DOMAIN
read -p "What WEB User do you want to use? " WEBUSER
read -p "What DB User do you want to use? " DBUSER
read -p "What DB password do you want to use? " DBPASS
read -p "What DB name do you want to use? " DBNAME
echo "**************************************";
echo "* Binded supplied domain to loopback *";
echo "127.0.0.1 ${DOMAIN} www.${DOMAIN}" >> /etc/hosts
echo "* Creating the needed file structure *";
mkdir -p docker/db html;
touch docker-compose.yml .env docker/xdebug.ini;
echo "* Writing contents of .env file data *";
echo "
CONTAINER_PREFIX=m2docker
SERVER_NAME=${DOMAIN}
SERVER_ALIAS=www.${DOMAIN}
DIRECTORY_NAME=${DOMAIN}
WEB_USER=${WEBUSER}
WEB_ROOT = /var/www/html
MYSQL_DB_HOST = \${CONTAINER_PREFIX}_db_1
MYSQL_DATABASE=${DBNAME}
MYSQL_ROOT_USERNAME=root
MYSQL_ROOT_PASSWORD=${DBPASS}
MYSQL_USER=${DBUSER}
MYSQL_PASSWORD=${DBPASS}
DOCKER_EXEC=docker exec
DOCKER_EXEC_INTERACTIVE=docker exec -i
DOCKER_EXEC_TTY=\${DOCKER_EXEC_INTERACTIVE} -t
" > .env
echo "* Writing docker-compose.yml content *";
echo "
version: \"3.6\"
services:
apache-php:
image: udovicic/echo:apache-php7.1
ports:
- \"80:80\"
expose:
- \"9000\"
volumes:
- ./docker/xdebug.ini:/etc/php/7.1/mods-available/xdebug.ini
- ./html:/var/www/html
environment:
- TERM=xterm-256color
- APACHE_RUN_USER=1000
networks:
default:
aliases:
- \${SERVER_NAME}
- \${SERVER_ALIAS}
db:
image: mysql:5.7
volumes:
- ./docker/db/data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: \${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: \${MYSQL_DATABASE}
MYSQL_USER: \${MYSQL_USER}
MYSQL_PASSWORD: \${MYSQL_PASSWORD}
redis:
image: redis:latest
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- \"8080:80\"
environment:
MYSQL_USERNAME: \${MYSQL_ROOT_USERNAME}
MYSQL_ROOT_PASSWORD: \${MYSQL_ROOT_PASSWORD}
" > .env
echo "* Writing xdebug.ini config contents *";
echo "
zend_extension=xdebug.so
xdebug.remote_autostart=0
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_connect_back=1
" > docker/xdebug.ini
echo "* Composer Install Mage 2 OS package *";
echo "**************************************";
su ${SUDO_USER} -c 'composer create-project --repository=https://repo.magento.com/ magento/project-community-edition html --ignore-platform-reqs';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.