Dockerizing your LAMP enviroment
I'm a (Big) fan of Docker, I've used it in my professional and personal projects since it first days. Things completely changed now and everyone is convinced that Docker is amazing. Docker now has gained popularity and maturity, and more companies started to use it in there prodiction. That was not the case 3 years ago.
Anyway, one of the first things I've used use Docker in is my development environment. In this post, I'll share with you how I used Docker and Docker compose to set up my development environment for php applications.
FROM php:5.6-apache # Install PDO MySQL driver # See https://github.com/docker-library/php/issues/62 RUN docker-php-ext-install pdo mysql RUN docker-php-ext-install pdo mysqli # Workaround for write permission on write to MacOS X volumes # See https://github.com/boot2docker/boot2docker/pull/534 RUN usermod -u 1000 www-data # Enable Apache mod_rewrite RUN a2enmod rewrite # Enable Apache mod_rewrite RUN a2enmod headers # Enable Apache mod_rewrite RUN a2enmod expires
site: build: . ports : - "9080:80" volumes: - ./www:/var/www/html/ links: - database php-myadmin: image: corbinu/docker-phpmyadmin ports: - "8080:80" environment: - MYSQL_USERNAME=<ROOT_PASSWORD> - MYSQL_PASSWORD=<DB_PASSWORD> links: - database:mysql database: image: mysql:5.5 ports: - "3333:3306" environment: - MYSQL_ROOT_PASSWORD=<ROOT_PASSWORD> - MYSQL_DATABASE=<DB_NAME> - MYSQL_USER=<DB_USER> - MYSQL_PASSWORD=<DB_PASSWORD> volumes: - ./data:/var/lib/mysql
As you see, I' using 3 linked containers: PHP, MySQL and PHPMyAdmin. Now all what you've to do, is to put your code in a folder named
www And run
docker-compose up. Voila!