Part 1, Install Docker and Docker Compose
Here’s a step-by-step guide to install Docker and Docker Compose on Debian 12 Bookworm
Step 1: Update System Packages
Ensure your system packages are up to date before starting the installation.
| 
					 0 1  | 
						sudo apt update && sudo apt upgrade -y  | 
					
Step 2: Install Required Dependencies
Install packages that allow apt to use HTTPS and required tools for adding Docker’s official repository.
| 
					 0 1  | 
						sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release -y  | 
					
Step 3: Add Docker’s Official GPG Key
You need to add Docker’s GPG key to verify the packages.
| 
					 0 1  | 
						curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg  | 
					
Step 4: Set Up Docker Repository
Add Docker’s official repository to your system.
| 
					 0 1  | 
						echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null  | 
					
Step 5: Install Docker Engine
Update the package database and install Docker.
| 
					 0 1 2  | 
						sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io -y  | 
					
Step 6: Verify Docker Installation
Check if Docker is installed and running.
| 
					 0 1  | 
						sudo systemctl status docker  | 
					
(Optional) Add your user to the docker group to avoid needing sudo for Docker commands:
| 
					 0 1  | 
						sudo usermod -aG docker $USER  | 
					
You’ll need to log out and log back in for this change to take effect, or apply
| 
					 0 1  | 
						newgrp docker  | 
					
Step 7: Install Docker Compose
Now install Docker Compose, which is a tool to define and run multi-container Docker applications.
| 
					 0 1  | 
						sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose  | 
					
Make the binary executable:
| 
					 0 1  | 
						sudo chmod +x /usr/local/bin/docker-compose  | 
					
Verify the installation:
| 
					 0 1  | 
						docker-compose --version  | 
					
Step 8: Enable Docker to Start on Boot
Enable the Docker service to automatically start on system boot.
| 
					 0 1  | 
						sudo systemctl enable docker  | 
					
Step 9: Test Docker and Docker Compose
You can run a simple Docker container to verify everything is set up properly:
| 
					 0 1  | 
						docker run hello-world  | 
					
For Docker Compose, create a simple YAML file (docker-compose.yml) and run it:
| 
					 0 1 2 3 4  | 
						version: '3' services:   hello-world:     image: hello-world  | 
					
Run the following command:
| 
					 0 1  | 
						docker-compose up  | 
					
Part 1, Summary
Now, Docker and Docker Compose are installed on your Debian 12 system, ready to manage containerized applications!
This guide will fit well into your blog post as a detailed tutorial for preparing Debian 12 to run Docker containers.
Part 2, Running Containers with Docker
Running Docker containers is straightforward once Docker and Docker Compose are installed. Here’s a basic guide on how to run containers.
Step 1: Pull a Docker Image
Docker images are pre-configured applications that you can run in containers. You can search for and pull images from Docker Hub.
For example, to pull an official Nginx image, run:
| 
					 0 1  | 
						docker pull nginx  | 
					
Step 2: Run a Docker Container
Once the image is pulled, you can start a container. For example, to run an Nginx container:
| 
					 0 1  | 
						docker run --name my-nginx -p 80:80 -d nginx  | 
					
--name my-nginx: Assigns a name to the container.-p 80:80: Maps port 80 on the host to port 80 on the container.-d: Runs the container in detached mode (in the background).nginx: The name of the image.
You can now visit http://localhost in your browser, and you should see the Nginx welcome page.
Step 3: Check Running Containers
To see all running containers:
| 
					 0 1  | 
						docker ps  | 
					
To see all containers, including stopped ones:
| 
					 0 1  | 
						docker ps -a  | 
					
Step 4: Stop and Remove Containers
To stop a running container:
| 
					 0 1  | 
						docker stop my-nginx  | 
					
To remove a stopped container:
| 
					 0 1  | 
						docker rm my-nginx  | 
					
You can also stop and remove containers in one command:
| 
					 0 1  | 
						docker stop my-nginx && docker rm my-nginx  | 
					
Running Containers with Docker Compose
Docker Compose is useful for managing multi-container environments with a single configuration file.
Step 1: Create a docker-compose.yml File
Here’s an example for running WordPress and MySQL:
| 
					 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  | 
						version: '3' services:   db:     image: mysql:5.7     volumes:       - db_data:/var/lib/mysql     restart: always     environment:       MYSQL_ROOT_PASSWORD: example   wordpress:     image: wordpress:latest     ports:       - "8000:80"     restart: always     environment:       WORDPRESS_DB_HOST: db:3306       WORDPRESS_DB_PASSWORD: example     depends_on:       - db volumes:   db_data:  | 
					
Step 2: Start the Containers
Navigate to the directory containing your docker-compose.yml file and run:
| 
					 0 1  | 
						docker-compose up -d  | 
					
This command will pull the required images, create containers, and start them in detached mode.
Step 3: Check Running Containers with Docker Compose
To see running containers managed by Docker Compose:
| 
					 0 1  | 
						docker-compose ps  | 
					
Step 4: Stop and Remove Containers
To stop the running containers:
| 
					 0 1  | 
						docker-compose down  | 
					
This command stops and removes all containers defined in the docker-compose.yml file.
Step 5: View Logs
To view logs of your services:
| 
					 0 1  | 
						docker-compose logs  | 
					
You can specify a service to view only its logs, for example:
| 
					 0 1  | 
						docker-compose logs wordpress  | 
					
Part 2, Summary
With Docker, you can easily run single containers, while Docker Compose allows for managing multi-container applications. This should give you the foundation to start running containers on Debian 12 and add more advanced setups to your blog post later.