Blog

Introduction to Docker

November 24, 2018
Docker containers

While working as a developer, whether you’ve just started or been working for years, it’s highly likely that you’ve met the term docker.

If you have been working with a docker for years, then you know all its advantages and disadvantages. In case you’ve just started, keep reading, as this might help you out to start with docker and introduce yourself with a whole new way of developing your web applications.

Docker is a platform for developers and sysadmins to develop, deploy, and run applications with containers.

You probably know the term:

It works on my machine.

As a web developer, you probably use some solution to run your application, such as wamp, xampp, lamp etc. This application is then deployed to a server or shared hosting after the development or during the development. In either of these two cases, you will often come across the problem that your local application does not work on the server at all.

Also in case you work with a team of developers on the same application, if everyone uses their own environment, with their own settings of the server, there are great chances that the code of the other developer will not work on your machine due to different server settings. Until you realize that the problem is in the difference of server settings, you have already lost the time that you could use to develop the application itself.

Docker makes all these problems gone. (The docker does many other things, but this is just an introduction).

To get the best understanding of how the docker works, let’s use the docker compose to easily run WordPress in an isolated environment built with Docker containers.

First, let’s start by installing docker engine and docker compose. Please follow instructions based on your operating system:

Installation of Docker Engine:

Installation of Docker Compose:

After installation of Docker Engine and Docker Compose, let’s start our WordPress project by creating an empty directory. Let’s say wordpress. Enter your directory.

For example, if you named your directory wordpress:

 

Create a docker-compose.yml file inside directory and paste following into the file:

Next, let’s build the project by running the command

inside your project directory. This run docker-compose up in detached mode. Pulling the needed Docker images and starts the WordPress, phpMyAdmin and database containers as shown in the example below.

Note: WordPress Multisite works only on ports 80 and/or 443. If you get an error message about binding 0.0.0.0 to port 80 or 443 (depending on which one you specified), it is likely that the port you configured for WordPress is already in use by another service.

At this point, WordPress should be running on port 8000 of your Docker Host, and you can complete the “famous five-minute installation” as a WordPress administrator.

If you are using Docker for Mac or Docker for Windows, you can use http://localhost as the IP address, and open http://localhost:8000 in a web browser.

There you go. Now you have a new place to develop your WordPress projects. Enjoy your development with Docker.

You Might Also Like

4 Comments

  • Reply John November 25, 2018 at 21:46

    Great tutorial, I’m looking forward to new posts.
    Thanks, this helped me!

  • Reply Eva December 2, 2018 at 16:30

    Will you make the same for symfony?

    • Dejan Vujanović
      Reply dejanvujanovic December 2, 2018 at 17:14

      Yes! Probably one of the next posts I am going to publish.

    Leave a Reply