Setting Up Docker for Local Development

Learn how to configure the local environment to run Rails on a Docker container in your system.

All the code written in this course and all commands executed are run inside a Docker container. Docker provides a virtual machine of sorts and allows you to replicate, almost exactly, the environment in which we wrote the code (see Why Docker?WhyDocker). If you don’t know anything about Docker, that’s ok. You should learn what you need to know here.

Docker is traditionally used for deploying applications and services to a production environment like AWS, but it can also be used for local development. You’ll need to install Docker, after which we’ll create a series of configuration files that will set up your local Docker container where all the rest of the coding in this course will take place.

Installing Docker

While the main point of Docker is to create a consistent place for us to work, it does require installing it on whatever computer you are using, and that is highly dependent on what that computer is!

Rather than try to capture the specific instructions now, you should head to the Docker Desktop page, which should walk you through how to download, install, and run Docker on your computer.

What is Docker?

You can think of Docker as a tool to build and run virtual machines. It’s not exactly that, but the mental model is close enough. There are some terms with Docker that are confusing, but they are critical to understand, especially if you experience problems and need help.

  • Image: A Docker image can be thought of as the computer you might boot. It’s akin to a disk image, and is the set of bytes that has everything you need to run a virtual computer. An image can be started or run with docker start or docker run.
  • Container: A Docker container is an image that’s being executed. It’s a computer that’s running. You can have multiple containers running from a single image. To use an object-oriented metaphor, if an image is a class, then a container is an instance of that class. You can run commands in a container with docker exec.
  • Dockerfile: The Dockerfile file contains instructions on how to build an image. It isn’t sophisticated. Most Dockerfiles are a series of shell invocations to install software packages. If an image is an object-oriented class, the Dockerfile is that class’ source code. An image is built with docker build.
  • Host: You’ll often see Docker documentation refer to “the host”. This is your computer. Wherever you are running Docker, that is the host.

To tie all this together (as in the figure “Docker Concepts” below), a Dockerfile is used to build an image, which is then started to become a container running on your host.

Get hands-on with 1200+ tech skills courses.