11  Get started with Docker

This guide is based on the excellent Docker step-by-step instructions on how to get started with Docker.

Some of the things you’ll learn and do in this guide are:

  1. Build and run an image as a container
  2. Update an image
  3. Share images using Docker Hub
  4. Deploy Docker applications with a SQLite database
  5. Share a directory from the host’s filesystem into the container (bind mounts).
  6. Store data in an external database running in a separate container
  7. Run applications using Docker Compose.
  8. Image builing best practices.
  9. Container orchestration and next steps.

Before you get to the hands on part of the guide, you should learn about containers and images.

11.1 What is a container?

Simply put, a container is a sandboxed process on your machine that is isolated from all other processes on the host machine. That isolation leverages kernel namespaces and cgroups, features that have been in Linux for a long time. Docker has worked to make these capabilities approachable and easy to use.

To summarize, a container:

  • Is a runnable instance of an image. You can create, start, stop, move, or delete a container using the DockerAPI or CLI.
  • Can be run on local machines, virtual machines or deployed to the cloud.
  • Is portable (can be run on any OS).
  • Is isolated from other containers and runs its own software, binaries, and configurations.

11.2 What is a container image?

When running a container, it uses an isolated filesystem. This custom filesystem is provided by a container image. Since the image contains the container’s filesystem, it must contain everything needed to run an application - all dependencies, configurations, scripts, binaries, etc. The image also contains other configuration for the container, such as environment variables, a default command to run, and other metadata.

11.3 Get the app

Before you can run the application, you need to get the application source code onto your machine.

  • Change directory into mnt/vdb
 cd /mnt/vdb
  • Clone the getting-started repository using the following command:
sudo git clone https://github.com/docker/getting-started.git

Now view the contents of the cloned repository in VS Code:

  • Navigate to the VS code menue at the top and choose ‘File’ > ‘Open Folder’ and insert: /mnt/vdb/getting-started/app (this will open a new window and you have to insert your SSH-key)

Inside the getting-started/app directory you should see package.json and two subdirectories (src and spec).

11.4 Next steps

For the rest of this guide, you’ll be working with a simple todo list manager that runs on Node.js. If you’re not familiar with Node.js, don’t worry. This guide doesn’t require any prior experience with JavaScript.

Next, you’ll learn hwo to containerize an application.