Get Started with Docker - Part 1 : An Intro to Docker
Tags: docker, tutorial, beginners, opensource
Published: 2024-02-23 20:48:45

[**Docker**](https://www.docker.com/) is a great way to run your self hosted applications and services on many different operating systems and types of hardware.

It's one of the easiest ways to get into self-hosting your own applications and a great way to learn without breaking things in the rest of your system.

In this series we're going to run through:

-   What Docker is and how it works?
-   How to get Docker installed on a Raspberry Pi or Windows Machine?
-   How to run your first Docker container?

___

## What is Docker?

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExZmRkeWo5a2ZvMXlxNHZ1ZDZrbTZpN3cwN3ZvcnBycWM2YjliY2cwbCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/OnJLRvXvAmvPW/giphy.gif">

[Docker](https://docker.com/) uses the **Docker Engine** to create containers that hold everything needed to run a particular piece of code or a executable program on almost any computer.

These containers are run independently from the rest of the machine similar to a virtual machine but with a lot less power needed.

The containers are isolated from the rest of the machine and can be run locally, remotely or in the cloud as their filesystem is self contained.

___

## Docker Containers

Containers can be used to run almost any piece of software like a File Server, Web Browser or Full Operating System.

Here's an explanation from Docker themselves.

>
"A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings." - ****What is a Container? | Docker.com****

What is a Container? | Docker

A container is a unit of software that packages code and its dependencies so the application runs quickly and reliably across computing environments.

[https://www.docker.com/resources/what-container/](https://www.docker.com/resources/what-container/)

These containers can be destroyed and then re-created quickly with the choice of either storing the data for the config to use again or reset to start fresh.

This allows you to upgrade or replace running containers with little to almost no down time, individually or all at once.

This can make keeping your infrastructure rolling along a lot easier and without anyone really noticing you've changed anything.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExbW93OHliMzN5amwzbjVwM2V3aWppNm5yamprNXM2c2xma2JsOWhkNiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/9x6fPJVGpq9HO/giphy.gif">

___

## Docker Images

**Docker Images** are created by members of the community, software companies and Docker themselves.

Think of them as a shrunk down version of the program you would normally download to install an application like Chrome.

A **Docker Image** contains a specific set of instructions and files to create the environment needed to run a program or execute code.

There's a whole catalogue of different images that you can download from the official [**Docker Hub**](https://hub.docker.com/)

![Docker Hub 01](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r2htlpfig4egqd0ggsao.png)

There are images for everything from a Website CRM application like Ghost, which is what this blog is running on to a full Ubuntu Operating system.

![Docker Hub 02](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vk6pcc585c99496598v2.png)

These images have everything in one package and run across several different environments with only a few variables needed to be changed.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExbHNyMDc0eTBsNTFhMzk2bW05MzR0bm1jMnQ1emFra3RwcGsydW9haiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/l3mZ8u9RJ4A9kPlK0/giphy-downsized-large.gif">

There are also different versions for different hardware architectures and you'll find more information and install instructions from the developer on their project pages.

![Docker Hub 03](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1r1tvt9foe6544aq1rd1.png)

___

## Docker Compose

**Docker Compose** files are the final part of the ecosystem you'll need to get familiar with when using Docker.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExa2g0MDNueHRvczRjemNmYnVqNHgxbGJwOXgwamR2NmZvMzYxeTE3cyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/34ZNcoaN5u4hi/giphy.gif">

These are YAML files with the .yml extension that contain the specific instructions needed to create the environment to run the Docker Image.

These will download the image, if you don't have it already locally so can be shared or used to run on another machine quickly. Most importantly it will run the same way every-time in a predictable, efficient way. The **Docker Compose** file is created using a text editor like Notepad++ in Windows or Nano/Vim in Linux.

Here's is an example of one that would spin up the docker version of Nginx Proxy Manager.

```
version: '3.8'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      # These ports are in format &lt;host-port&gt;:&lt;container-port&gt;
      - '80:80' # Public HTTP Port
      - '443:443' # Public HTTPS Port
      - '81:81' # Admin Web Port
      # Add any other Stream port you want to expose
      # - '21:21' # FTP

    # Uncomment the next line if you uncomment anything in the section
    # environment:
      # Uncomment this if you want to change the location of
      # the SQLite DB file within the container
      # DB_SQLITE_FILE: "/data/database.sqlite"

      # Uncomment this if IPv6 is not enabled on your host
      # DISABLE_IPV6: 'true'

    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
```

You can usually find the **Docker Compose** file on the project page on **Docker Hub** or **GitHub** when you get an image if you're looking for more to try out.

You can also find a whole load of example Docker Compose files here for inspiration and to run once you've got the Docker Engine installed.

GitHub - docker/awesome-compose: Awesome Docker Compose samples

[https://github.com/docker/awesome-compose](https://github.com/docker/awesome-compose)

These are ran using the **docker command** below usually unless stated otherwise. This runs the container in detached mode so you can continue to use the terminal

```
docker-compose up -d
```

___

## Docker Run

You can use a **Docker Compose** file or instead just a **Docker Run Command** to start running an application.

Here's how to run **NGINX Proxy Manager** using the **Docker Run Command**

```
docker run -d \
    --name=nginx-proxy-manager \
    --restart unless-stopped \
    -p 8181:8181 \
    -p 8080:8080 \
    -p 4443:4443 \
    -v /docker/appdata/nginx-proxy-manager:/config:rw \
    jlesage/nginx-proxy-manager
```

If you copy and paste the above into a terminal then it will run **Nginx Proxy Manager** just like the **Docker Compose** file.

This may come in handy on systems where you can't easily navigate to the correct folder but can run Docker commands. It's also a very quick way to spin up containers for testing.

Now you've had a quick Intro to Docker, we're ready to install this to the operating system and device of your choice.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExdGJ1OHg1eTQ5Mzd4OXcyeWFrajU4MmJyeDg0bmV2OWFkaXRqc25hNSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/z8gtBVdZVrH20/giphy.gif">

___

## Docker Engine

To use **Docker** you need to install the **Docker Engine** on your chosen Operating system which will set up everything in the background to get things running.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExbnhzY2N4dmM2MmZycWl3OG50Zm1zY3d0dWQzZW1jeWE4aXRyeTl3cCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/l2JefbKQ8JWybbyP6/giphy.gif">

### Raspberry Pi (Linux)

The Raspberry Pi 4 is a powerful machine for it’s small form factor and makes the perfect candidate for experimenting with Docker.

Linux is the best overall operating system and platform for Docker in my humble opinion for performance and learning potential. I'm running Docker on a Raspberry Pi 4, Raspberry Pi 3, Raspberry Pi Zero and through a Linux VM on my Windows Desktop.

There's a simple script provided directly by Docker themselves that you can run to automate the installation process

![Docker Convenience Script](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/176hpev6g9mhtb2xyo0s.png)

On the flipside, it can be a bit daunting if you're unfamiliar with Linux when it comes to troubleshooting. This can be a great way to learn the OS as a whole.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExcHdmM2JzczM5c2N2OXJmYjRwZnQxZmdzazQ1M2dxNm84bWJ2aWVrdCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/3og0ICG4WxdKSRzE3K/giphy.gif">

We'll go over the install in a future guide in this series and it'll be linked here

___

### Windows 11

This can also be run on Windows machine by installing Docker Desktop which give you a GUI to manage your containers.

![Docker Desktop Windows](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f21cx0z3ghwyz66jbqud.png)

![Docker Desktop Windows Download](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zejt8t1f3fyr3r9bfm6n.png)

It has a few quirks and specific ways in which the file paths work for the containers compared to Linux.

This was the way I first started using Docker. It taught me a lot of the fundamentals and being in Windows can make it easier to troubleshoot. I personally still use Docker Desktop on my own Windows Laptop for using Docker on the go.

**Docker Desktop** on Windows will give you the option to use WSL2 (Windows Subsystem for Linux). This is a full Linux installation running under the hood of Windows and lets you use Linux commands for Docker just like a full VM.

To get the best performance of our **Docker** on Windows you should get WSL2 but it's optional.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExM2l0aXhoMXIyYnNnOHVhcDN6emFsa2swaWQ2c2d4ZnZxcXMwYmh1biZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/AliO819Kp3aus/giphy.gif">

We'll go over the install in a future guide in this series and it'll be linked here

___

Congratulations, that's the nuts and bolts of Docker but in the rest of this series we're going to go through exactly how to install Docker on Linux (Raspberry Pi) and Windows for those of you who want to try it out.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExNnZkY2R5NmY3MmNteGZ2enpiajdxazR4ejd0b2Vib3F0bTF1N3NiNSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/UZA15w44oCT1m/giphy.gif">

Join us next time for Part 2a - How to Install Docker on a Raspberry Pi using Linux

[Part 2a - How to Install Docker on a Raspberry Pi using Linux](https://dev.to/reprodev/get-started-with-docker-part-2a-raspberry-pi-linux-install-guide-4hl9)

___

Don't forget to explore the rest of our website as we build out more content. Stay tuned for more tutorials, tips, and tricks to help you make tech work for you.

___