Docker Community Forums

Share and learn in the Docker community.

Guidelines to move from Ansible to Docker


(Yannisc) #1

Hi!

I’m very new to Docker, but from what I read and understand is really promising.

I currently use Ansible in order to setup new dedicated machines with Nginx, MariaDB, PHP etc. in order to host Drupal websites.

I wonder what is the best practice on the following questions:

  1. What should I use as a base image? Centos 6 (the one I know and currently use) or Nginx or something else?
  2. Should I use one Dockerfile or more?
  3. What is the best way to deploy/setup on Hetzner’s machines? What should the base installation on these machines be? Is there an automatic way to set them up?

How could I get answers on the above? Could you point me to a relevant tutorial or something? Maybe a consultant?

Thanks in advance for any help


(Trevorsullivan) #2

Hello @yannisc, I’m not a Docker expert, and I’ve never touched Ansible, but perhaps I can offer you some insight. :slight_smile: Let me answer your questions according to their numbers.

  1. I don’t know for sure, but from my observations thus far, the Docker images in the Docker Hub are rather large and not “lightweight.” In fact, I don’t even know if you’re required to use a Linux OS as the base image. I’m pretty sure there is a “scratch” image (or similar) that you can build off of, which is entirely empty itself. I recently posted a thread asking for guidance on Docker-izing applications, in general, and no one responded. Have you looked into CoreOS or RancherOS?

  2. Each Dockerfile builds one image, and as best I can tell, your application should be divided into multiple Docker images. When instantiated, the images become “containers.” Docker Compose is the utility that “orchestrates” multiple containers together, to offer up a complete application or service.

  3. I’m not sure about this service provider, but the process should be fundamentally similar for any VPS or cloud provider. You instantiate the host operating system, deploy the Docker daemon, and connect to it. I doubt there’s a Docker Machine “driver” for that provider (I could be wrong), but you should be able to use docker-machine ssh to connect to any Docker daemon.

Cheers,
Trevor Sullivan
Microsoft MVP: PowerShell


https://twitter.com/pcgeek86


(Nathan Le Claire) #3

Personally, I favor the “Operating System”-level base images (such as debian, centos) since you can bake exactly what you need in and the Dockerfile covers every single thing needed to run your application. This keeps the deps explicit instead of implicit and also ensures that you don’t get unneeded extra stuff that something like php:latest might have. The “full stack” library images are great for getting started and playing around though.

Approximately one Dockerfile (and ensuing container) per service/UNIX process. In your case you will most likely bake the PHP source code into a container with Apache and mod_php (or equivalent). This will be the actual webserver container which runs PHP code, and then you will create another container for mariadb which is on the same docker network as the PHP container. You can connect to the DB container from the Apache container using DNS (container name).

Depends on how large your setup is, installing Docker is fairly easy (running the script at get.docker.com will install it for your OS, or you can use that script as a guide to install from packages). Indeed, you may not need to throw out Ansible altogether, but rather continue using it in a reduced role as a tool to bootstrap and secure instances that run Docker.