Chapter 1. Docker in Production

In this chapter, we will be looking at Docker in production, pulling all the pieces together so you can start using Docker in your production environments and feel comfortable doing so. Let's take a peek at what we will be covering in this chapter:

  • Setting up hosts and nodes
  • Managing hosts and containers
  • Using Docker Compose
  • Extending to external platforms
  • Security

Where to start?

When we start thinking about putting Docker into our production environment, we first need to know where to start. This sometimes can be the hardest part of any project. We first need to start by setting up our Docker hosts and then start running containers on them. So, let's start here!

Setting up hosts

Remember, as it was mentioned in the earlier chapter, that setting up hosts will require us to tap into our Docker Machine knowledge. We can deploy these hosts to different environments, including cloud hosting. To take a walk down memory lane, let's look at how we go about doing this:

$ docker-machine create --driver <driver_name> <host_name>

Now, there are two values that we can manipulate: <driver_name> and <host_name>. The host name can be whatever you want it to be. But I recommend that it should be something that would help you understand its purpose. The driver name on the other hand has to be the location where you want to create the host. If you are looking at doing something locally, then you can use VirtualBox or VMware Fusion. If you are looking at deploying your application to a cloud service, you can use something like Amazon EC2, Azure, or DigitalOcean. Most of these cloud services will require additional details to authenticate who you are and where to place the host:

For example, for AWS, you would use:

$ docker-machine create --driver amazonec2 --amazonec2-access-key <AWS_ACCESS_KEY> --amazonec2-secret-key <AWS_SECRET_KEY> --amazonec2-subnet-id east-1b amazonhost

You can see that you will need the following:

  • Amazon access key
  • Amazon secret key
  • Amazon subnet ID

Setting up nodes

Next, we want to set up the nodes or containers to run on the hosts that we have recently created. Again, using a combination of Docker Machine with the Docker daemon, we can do this. We first must use Docker Machine to point to the Docker host that we want to deploy some containers on:

$ docker-machine env <host_name>
$ eval "$(docker-machine env <host_name>)"

Now we can run our normal Docker commands against this Docker host. To do this, we will simply use the Docker command-line tools. To deploy the containers, we can pull the following images:

$ docker pull <image_name>

Or, we can run a container on a host:

$ docker run -d -p 80:80 nginx
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset