How-To: Docker

Docker is a platform that allows developers to easily create, deploy, and run applications in containers. Containers are lightweight, portable, and self-sufficient environments that encapsulate an application and all its dependencies.

Docker enables applications to run in containers that can be used on any system: a developer’s laptop, systems on premises, or in the cloud.

This guide serves as an introduction to Docker. Docker is a vast ecosystem that can take many forms. If you are interested in exploring/learning more about Docker, check out the tutorials linked in the Resources section at the bottom of this page.

Install Docker

To get started with Docker, you need to install it on your machine. The installation process varies depending on your operating system. You can find detailed instructions for installing Docker on various platforms on the Docker website here.

Dockerfile

A Dockerfile is a text file that contains instructions for building a Docker image. An image is a lightweight, stand-alone, executable package that includes everything needed to run a piece of software, including the code, a runtime, libraries, environment variables, and config files.

To create a Dockerfile, you need to define the base image, copy the application code into the image, and configure the image to run the application. You can also set environment variables, specify the working directory, and expose ports.

Here is an example Dockerfile for a C application that uses a Makefile to compile:

FROM ubuntu:latest

RUN apt-get update && apt-get install -y gcc make

WORKDIR /app

COPY . .

RUN make

CMD ["./app"]

Let us take a closer look at the Dockerfile:

Building a Docker Image