8 of 10: More Docker Containers.

Brian KingBrian King
3 min read

Homelab | LXD Manager | Docker | Docker Desktop | Deno | MariaDB | Portainer | More Docker | Docker Swarm | CrowdSec

TL;DR.

I will create, and configure, another container for Docker. I will call it 'docker2', and I will enable nesting within the container. I will then install Docker, change the Docker IP address, test the installation, and change my settings (if needed).

An Introduction.

In a previous post, I installed Docker in a LinuX Container. This time, I will... install Docker in a Linux container. However, I'll be using a modified, and simplified, process to achieve this outcome.

The purpose of this post is to formalise a process for installing Docker in Linux containers.

The Big Picture.

My next post is all about installing, and setting up, a Docker Swarm solution. A prerequisite for running a Docker Swarm is to have at least 3 Docker servers.

Beyond experimenting with Docker Swarm, I will also reference this post while learning to build infrastructure as code (IaC) solutions. I will need to practice making state files (For TerraForm) and Playbooks (for Ansible), so deploying Docker containers seems like a good candidate for learning IaC automation.

Installing Docker in a Container. Again.

  • From the homelab terminal (CTRL + ALT + T), I create a new container called 'docker2' where I set nesting to true:
lxc launch ubuntu:22.04 docker2 -c security.nesting=true

NOTE: Nesting allows the 'docker2' container to host another container system, e.g. Docker.

  • I bash into the new container:
lxc exec docker2 -- bash
  • I update and upgrade the 'docker2' container:
sudo apt clean && sudo apt update && sudo apt dist-upgrade -y && sudo apt autoremove -y
  • I install Docker:
sudo apt install -y docker.io

NOTE: For the sake of brevity, I have skipped:

Changing the Docker IP Address.

  • I open (or create) a file in Nano:
sudo nano /etc/docker/daemon.json
  • I add the following object, save the changes, and exit Nano:
{
    "bip": "172.17.0.2/24"
}
  • I restart Docker:
sudo service docker restart

Testing the Docker Installation.

  • I run the 'hello-world' Docker project:
sudo docker run hello-world

Other Docker Settings.

  • If the 'hello-world' test fails, I will need to exit the container:
exit
  • I configure the docker socket for the 'docker2' container:
lxc config device add docker2 docker-dev unix-char path=/var/run/docker.sock
  • I bash back into the 'docker2' container:
lxc exec docker2 -- bash
  • I run the 'hell-world' project again:
sudo docker run hello-world

The Results.

This post provides a step-by-step guide on creating and configuring a new Docker container called 'docker2', enabling nesting, installing Docker, changing the Docker IP address, and testing the installation. By following these instructions, I can easily set up, and manage, Docker in a LinuX Container.

In Conclusion.

Spinning up, and tearing down, Docker containers may seem whimsical, but the ephemeral nature of containers is an important part of my homelab experience. I'm working my way toward an integrated solution for the 12 Startups project. The more posts I publish, the closer I get to the Agile-DevSecOps-CI/CD Nirvana.

Until next time: Be safe, be kind, be awesome.

Homelab | LXD Manager | Docker | Docker Desktop | Deno | MariaDB | Portainer | More Docker | Docker Swarm | CrowdSec

0
Subscribe to my newsletter

Read articles from Brian King directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Brian King
Brian King

Thank you for reading this post. My name is Brian and I'm a developer from New Zealand. I've been interested in computers since the early 1990s. My first language was QBASIC. (Things have changed since the days of MS-DOS.) I am the managing director of a one-man startup called Digital Core (NZ) Limited. I have accepted the "12 Startups in 12 Months" challenge so that DigitalCore will have income-generating products by April 2024. This blog will follow the "12 Startups" project during its design, development, and deployment, cover the Agile principles and the DevOps philosophy that is used by the "12 Startups" project, and delve into the world of AI, machine learning, deep learning, prompt engineering, and large language models. I hope you enjoyed this post and, if you did, I encourage you to explore some others I've written. And remember: The best technologies bring people together.