I am new to Docker and I am having a hard time applying its core technology to my present web development. Using MAMP, you just need to download the app, put your PHP/HTML files on /htdocs, start servers, then go to http://localhost:8888/ to see your webapp. Now, using docker, I’m wondering how can I do the same. What I’ve done so far is to pull http, php and mysql images from the Docker Hub.
I’m working on a Mac OS X Yosemite (10.10.1) with boot2docker v1.4.1 and VirtualBox 4.3.20.
Docker can help streamline development teams by packaging all code and dependencies like system libraries and settings. Docker is similar to a virtual machine, but much more efficient. Packing up code in a “container” improves application performance and allow the application to run in different environments.
Do Not Use Docker if You Want to Light Up Development and Debugging. Docker was created by developers and for developers. It provides environment stability: a container on the development machine will work exactly the same on staging, production, or any other environment.
Docker is a great way to provide consistent development environments. It will allow us to run each of our services and UI in a container. We'll also set up things so that we can develop locally and start our dependencies with one docker command.
Docker helps to ensure that all the developers have access to all the necessary bits and pieces of the software they work on. So if someone adds software dependencies, everyone has them when needed. If it is just one developer, there is no such need.
You can now use docker-compose
and a docker-compose.yml file to accomplish the same thing as fig.
Finding containers for each service and linking them together isn't the easiest thing. The docker-compose file from The damp github project (pasted below for posterity) is a good start for how to get the apache, php, and mysql services all running with a docker-compose -f docker-compose.yml up
command.
proxy:
image: jwilder/nginx-proxy
ports: ['80:80']
volumes: ['/var/run/docker.sock:/tmp/docker.sock:ro']
environment: [DEFAULT_HOST=damp.dev]
database:
image: 'mysql:5.7'
ports: ['3306:3306']
environment: [MYSQL_ROOT_PASSWORD=password]
phpmyadmin:
image: corbinu/docker-phpmyadmin
links: ['database:mysql']
environment: [MYSQL_USERNAME=root, MYSQL_ROOT_PASSWORD=password, VIRTUAL_HOST=phpmyadmin.damp.dev]
damp:
image: httpd
volumes: ['~/damp/damp:/usr/local/apache2/htdocs']
environment: [VIRTUAL_HOST=damp.dev]
Once you do that _and put an entry for damp.dev 127.0.0.1
in your hosts file, anything you mount in ~/damp/damp (per that second to last line) will be put in the htdocs of the docker container and served up on damp.dev/[whatever].
damp is just the first example I found poking around on how to replicate MAMP with docker. The most important thing to note is that you can use docker-compose
instead of fig
. Compose is based directly on the Fig codebase and is backwards-compatible with Fig applications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With