Ultimate Docker Guide

Docker is easy to use and helpful to get things up and going fast. If you aren't using docker and you want to, then this guide will get you started.
Ultimate Docker Guide

Introduction

In a world where data privacy and security are becoming increasingly important, many individuals and organizations are turning to self-hosting as a way to take control of their online presence. With the rise of containerization technologies like Docker, setting up a self-hosted environment has become easier than ever.

Docker has become an essential tool in modern development and deployment processes, offering a streamlined way to manage containers, services, and applications. In this guide, I aim to walk you through the setup process for Docker on a Linux system, breaking things down into actionable steps. Whether you're dabbling with Docker for the first time or looking to refine your setup, this post is designed to help you navigate the process with clarity. I'll also share links to some of my recommended containers, which I’ve personally found helpful for various projects.

Throughout this guide, I'll emphasize the prerequisites, key commands, and some useful tools that can enhance your Docker experience. From understanding how to install Docker to leveraging containers like Portainer or MySQL, this guide will provide practical insights you can immediately apply. By the end, my hope is that you'll not only have a functioning Docker environment but also feel more confident exploring its potential in your projects.

References

How to Use Docker Compose V2
This guide provides a brief introduction to Docker Compose V2 and explains how to install and use it.
Install
Learn how to choose the best method for you to install Docker Engine. This client-server application is available on Linux, Mac, Windows, and as a static binary.

Prerequisites

  • Internet Connection
  • Up-to-date Server
  • Sudo/Administrator Privileges

Overview

In this article, I am using Rocky Linux which is a RHEL based Linux operating system. Most of this should be applicable to any Linux OS. If you are unsure about the commands used, you can consult Grok, ChatGPT or the basic search of the Internet.

Data Folder Creation

In the root directory, it would be best to create a folder that you can use for data and such. You should create a group as well to give access to this folder. It would be best practice to create another account to maintain permissions and if you are going to be using FTP.

sudo addgroup data
sudo adduser [username] data
cd /
sudo mkdir data
sudo chown [username]:data /data
sudo chmod -R 775 /data

# set default permissions for new files and folders
sudo chmod g+s /data

# install Access Control List
sudo dnf -y install acl

# setfacl on them to enforce this
sudo setfacl -R -m u:[username]:rwx /data
sudo setfacl -R -m g:data:rwx /data

# setfacl defaults
sudo setfacl -dR -m u:[username]:rwx /data
sudo setfacl -dR -m g:data:rwx /data

# reboot for settings to take effect
sudo reboot

Install Docker

Let’s begin with installing Docker, now Docker Compose V2 did get released, so I am including a few extra steps if you are intended to upgrade.

# if you already have docker installed and need to reinstall
# stop docker
sudo systemctl stop docker

# Remove Previous Docker Packages
sudo dnf remove docker docker.io containerd

# Clean DNF cache
sudo dnf clean all

# Update Packages
sudo dnf update -y

# Install Additional Components for Docker
sudo dnf install -y curl

# Add the official Repo
sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo <https://download.docker.com/linux/centos/docker-ce.repo>

# Update Packages
sudo dnf update -y

# Install Docker Engine
sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Start and enable Docker
sudo systemctl start docker
sudo systemctl enable docker

# Verify
docker --version
docker compose version

# If you previously installed Docker, verify your existing containers
docker ps -a

Docker User Setup

Next we need to set the account we are using for docker implementation access to Docker without Sudo Privileges. This could be a security issue so proceed if you want to. You can use multiple accounts as well.

sudo adduser dockeruser
sudo usermod -aG docker dockeruser
sudo reboot

Docker Maintenance

Unfortunately, Docker doesn't maintain itself. If you don't keep an eye on it, it can fill up your storage fast. I learned this the hard way.

Image Maintenance

docker image prune will remove all images not being used and not attached to containers.

Volume Maintenance

docker volume prune will remove all volumes not being used and not attached to containers.

Network Maintenance

docker network prune will remove all unused networks.

Container Maintenance

docker container prune will remove all unused containers. Be careful with this one.

  • Link to WatchTower
  • Link to Portainer
  • Link to MySQL
  • Link to Nginx Proxy Manager

Conclusion

In this guide, we explored the essentials of setting up and managing Docker on a Linux system, emphasizing practical steps to streamline your containerized workflows. From creating a dedicated data folder and setting up permissions to installing Docker and its components, I aimed to provide a clear path for beginners and intermediate users alike. We also discussed setting up user accounts for Docker access and highlighted ongoing maintenance tasks, such as pruning images, volumes, and networks, to ensure your system stays efficient and manageable. By addressing these foundational steps, you’re now equipped to deploy and manage containers effectively, whether for personal projects or professional environments.

As we dove into recommended Docker containers like WatchTower, Portainer, and MySQL, I wanted to emphasize the flexibility and power containerization offers for various use cases. These tools, paired with a well-maintained Docker environment, can significantly enhance your ability to self-host, organize, and secure your applications. My hope is that by following this guide, you’ve gained both the technical knowledge and confidence to take control of your Docker setup. With proper care and attention, your containerized ecosystem can become a reliable and scalable solution for your needs. I encourage you to experiment, refine your processes, and continue growing your expertise in Docker and containerization.


Full Disclosure

All information and images have been provided by Docker. I am using the provided press kit for this article. Their website and my use of their programs are conveyed in this article. Most of this article is comprised of facts and opinions. AI (specifically Grok and Notion AI) was used in the creation of this post. The featured background image was created by andyoneru and is available on Unsplash. I added a blur and a gradient overlay with some text. The following images have been pulled or screenshotted from the respective websites/applications. I do not own this content.

Subscribe to Hi! I'm Harley newsletter and stay updated.

Don't miss anything. Get all the latest posts delivered straight to your inbox. It's free!
Great! Check your inbox and click the link to confirm your subscription.
Error! Please enter a valid email address!