docker moby

Docker and how to make your life easier

Docker is a new way to use virtual machines (someone expert that read this, not hate me, it’s a way to show what it is). Docker represents an easy step to install services in our machine without installing it. This means, is like virtual machine using your own hardware instead of virtualize it and where you can install things. It’s complex to explain, because Docker are half path between your own computer and Virtual Machine.

The best way to understand what is and why use it is create a basic example. We are web developers, the best is create an Apache Image with PHP and execute some code.

Install Docker

Let’s try it. First install Docker, this is important. If you don’t install the examples in this article couldn’t work!

You can download a copy of Docker here:

Install and …. continue.

Now it’s time to create containers. Docker have containers, container is a service installed and you can apile containers to add more services. Let’s go to work and stop rare words!!

Create Image

This tutorial talk about create an image that you can use and reuse. Time to create. Move to a new folder and create a file called Dockerfile and add the next lines:

It’s a two line file. Simple instructions:

  • FROM chialab/php:5.6-apache: tell what docker image you want to use. I’m choosing chialab images because have a lot of libraries installed. You can choose other one if you want. Feel free, I’m always use it because have all I need for development. Search images here:
  • ENV APACHE_LOG_DIR /var/www/html : Tell image internal environment variable.

Time to build. We have a simple Dockerfile and now need to build our image, open terminal window and move to the Dockerfile folder and execute command:

We was build apache image, execute next command to see your images:

Use Image

Now it’s time to use it. Then, create a index.php page with phpinfo() instruction.

Only one more step and we are done. Time to execute the magic command:

What’s the meaning of commands?

  • docker run: tells to execute image
  • -v: is for mount volumes. I’m telling that folder $PWD (it’s system variable for actual folder) maps to /var/www/html inside image
  • -p: map port 80 in our computer to port 80 in image.
  • apache: Docker image name

If you aren’t using Mac Os X or any Linux based OS you can change $PWD for other folder:

And finally, open your browser and write https://localhost You will see a phpinfo() information:


You are running a web server now with apache.Thanks to docker it’s easy to create environments without install any software in our computers.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *