Skip to content

Commit

Permalink
Improve Docker explanation
Browse files Browse the repository at this point in the history
- More of an overview / how it works
- Explain in which circumstances it might be useful
- Simplify the example container
- Mention PHPDocker.io
- Two links to Docker Hub, one with the official images
- brief security warning
  • Loading branch information
wturrell authored Oct 9, 2016
1 parent 8cf2fa9 commit 24dfa32
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions _posts/13-03-01-Docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,36 @@ anchor: docker

## Docker {#docker_title}

Beside using Vagrant, another easy way to get a virtual development or production environment up and running is [Docker].
Docker helps you to provide Linux containers for all kind of applications.
There are many helpful docker images which could provide you with other great services without the need to install
these services on your local machine, e.g. MySQL or PostgreSQL and a lot more. Have a look at the [Docker Hub Registry]
[docker-hub] to search a list of available pre-built containers, which you can then run and use in very few steps.
[Docker] is so called because it's all about containers. It's a lightweight alternative to a fully-fledged Vagrant VM. PHP's OOP is perhaps a helpful analogy to understanding it: think of Docker "images" as classes and "containers" as instances of them. For a typical LAMP application, you might have a web server container, another for the PHP-FPM process and a third for the MySQL server. Your project files - PHP, HTML, other assets, database contents – all remain on your host computer. You can create containers from the command line, or build a `docker-compose.yml` file that specifies which to use and how they communicate ("link") with one another.

Docker may help if you're developing multiple websites and want the separation that comes from installing each on it's on virtual machine, but don't have the necessary disk space or the time to keep everything up to date. It's efficient: the installation and downloads are quicker, you only need to store one copy of each image however often it's used, containers need less RAM and share the same OS kernel, so you can have more servers running simultaneously, and it takes a matter of seconds to stop and start them, no need to wait for a full server boot.

### Example: Running your PHP Applications in Docker

After you [installed docker][docker-install] on your machine, you can start an Apache with PHP support in one step.
The following command will download a fully functional Apache installation with the latest PHP version and provide the
directory `/path/to/your/php/files` at `http://localhost:8080`:
After [installing docker][docker-install] on your machine, you can start a web server with one command.
The following will download a fully functional Apache installation with the latest PHP version, map `/path/to/your/php/files` to the document root, which you can view at `http://localhost:8080`:

{% highlight console %}
docker run -d --name my-php-webserver -p 8080:80 -v /path/to/your/php/files:/var/www/html/ php:apache
{% endhighlight %}

After running `docker run` your container is initialized and running.
If you would like to stop or start your container again, you can use the provided name attribute and simply run
`docker stop my-php-webserver` and `docker start my-php-webserver` without providing the above mentioned parameters
again.
This will initialize and launch your container. `-d` makes it runs in the background. To stop and start it, simply run `docker stop my-php-webserver` and `docker start my-php-webserver` (the other parameters are not needed again).

### Learn more about Docker

The commands mentioned above only show a quick way to run an Apache web server with PHP support but there are a lot
more things that you can do with Docker. One of the most important things for PHP developers will be linking your
web server to a database instance, for example. How this could be done is well described within the [Docker User Guide]
[docker-doc].
The command above shows a quick way to run a basic server. There's much more you can do (and thousands of pre-built images in the [Docker Hub][docker-hub].) Take time to learn the terminology and read the [Docker User Guide][docker-doc] to get the most from it, and don't run random code you've downloaded without checking it's safe – unofficial images may not have the latest security patches. If in doubt, stick to the [official repositiories][docker-hub-official].

The [PHPDocker.io] site will auto-generate all the files you need for a fully-featured LAMP/LEMP stack, including your choice of PHP version and extensions.

* [Docker Website][Docker]
* [Docker Installation][docker-install]
* [Docker Images at the Docker Hub Registry][docker-hub]
* [Docker User Guide][docker-doc]

* [Docker Hub][docker-hub]
* [Docker Hub - official images][docker-hub-official]

[Docker]: http://docker.com/
[docker-hub]: https://hub.docker.com/
[docker-hub-official]: https://hub.docker.com/explore/
[docker-install]: https://docs.docker.com/installation/
[docker-doc]: https://docs.docker.com/userguide/
[PHPDocker.io]: https://phpdocker.io/generator

0 comments on commit 24dfa32

Please sign in to comment.