Skip to content

Instantly share code, notes, and snippets.

@lucashorton
Last active August 29, 2015 14:04
Show Gist options
  • Save lucashorton/0d9eb2886f673ac34295 to your computer and use it in GitHub Desktop.
Save lucashorton/0d9eb2886f673ac34295 to your computer and use it in GitHub Desktop.
Docker LAMP Development Environment How-to

Docker LAMP Development Environment How-to

Before first run

Download Docker and boot2docker from https://www.docker.com/

Install Docker and boot2docker using the installer

Initialize boot2docker

boot2docker init

Follow the directions on the screen to set the DOCKER_HOST

###Create a data container for the web application

docker run -v /app --name app ubuntu true

###Create a data container for MySQL

docker run -v /var/lib/mysql --name data ubuntu true

Run MySQL

docker run -d -p 3306:3306 --volumes-from data -e MYSQL_ROOT_PASSWORD="changeme" --name db mysql

Note: modify MYSQL_ROOT_PASSWORD="changeme" to set a root password for your MySQL instance.

Run Apache

docker run -d --link db:db -p 8080:80 --volumes-from app --name web tutum/apache-php

Get Boot2Docker IP address

boot2docker ip

##On each run

###Boot boot2docker

boot2docker up

Start MySQL and Apache containers

docker start db web

Share the app container using Samba

docker run --rm -v /usr/local/bin/docker:/docker -v /var/run/docker.sock:/docker.sock svendowideit/samba app

Get Boot2Docker IP address

boot2docker ip

To develop applications

Mount the app share

Using the address returned from boot2docker ip, connect to the app Samba (Windows) share. On OSX, activate Finder and press Command-K or select Go->Connect to Server... In the address bar, enter smb://smb://192.168.59.103/app and click connect. A volume will be then mounted at /Volumes/app

Connect to MySQL

Using the address returned from boot2docker ip, connect to the MySQL server. The username is root and the password is the root password you set for MYSQL_ROOT_PASSWORD.

Configure your application

To use MySQL, first create a new table and user using your MySQL client of choice. When connecting the web application to the MySQL server, use db for the hostname.

Browse your web application

Your web application is running on port 8080. To connect to it via browser, use http://YOUR-BOOT2DOCKER-IP:8080.

To shutdown

Stop boot2docker

boot2docker down
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment