Docker Community Forums

Share and learn in the Docker community.

When Should You Use Docker or Ansible?

docker

(gracylayla) #1

Now that you know a little bit about each tool, it’s time to decide when you should use Docker or Ansible. If I were you, I would just use both because they each solve different problems.

When to Use Docker

I like to think of it like this. If I’m running a service, such as nginx, Redis, PostgreSQL, or my own web applications then I’m most definitely going to use Docker.

This works great in development, testing and production because the same images get ran across each environment. If I’m hacking away on some code on my dev box then I can be confident it will work the same way in production.

Docker gives you a number of tools to help move these images between servers, and even perform complicated tasks such as load balancing services and performing rolling updates.

When to Use Ansible

I like to use Ansible for things that exist at the server level but aren’t necessarily processes that run. For example, if I wanted to create a deploy user on the system, then it makes sense to use Ansible. This is something that needs to exist on the main system, not inside of Docker.

Ansible is also great for bootstrapping Docker itself. That means installing Docker, along with Docker Compose or any other Docker related tools you need to configure (such as Docker Swarm).

Basically, I would reach for Ansible for performing tasks that set up core functionality for the server to do its thing. That includes the above, along with doing things like hardening SSH’s configuration to make it more secure, or copying over config files that I plan to volume mount with Docker.