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.
Step 2: Install Required Dependencies
Install packages that allow apt
to use HTTPS and required tools for adding Docker’s official repository.
Step 3: Add Docker’s Official GPG Key
You need to add Docker’s GPG key to verify the packages.
Step 4: Set Up Docker Repository
Add Docker’s official repository to your system.
Step 5: Install Docker Engine
Update the package database and install Docker.
Step 6: Verify Docker Installation
Check if Docker is installed and running.
(Optional) Add your user to the docker
group to avoid needing sudo
for Docker commands:
You’ll need to log out and log back in for this change to take effect, or apply
Step 7: Install Docker Compose
Now install Docker Compose, which is a tool to define and run multi-container Docker applications.
Make the binary executable:
Verify the installation:
Step 8: Enable Docker to Start on Boot
Enable the Docker service to automatically start on system boot.
Step 9: Test Docker and Docker Compose
You can run a simple Docker container to verify everything is set up properly:
For Docker Compose, create a simple YAML file (docker-compose.yml
) and run it:
Run the following command:
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:
Step 2: Run a Docker Container
Once the image is pulled, you can start a container. For example, to run an Nginx container:
--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:
To see all containers, including stopped ones:
Step 4: Stop and Remove Containers
To stop a running container:
To remove a stopped container:
You can also stop and remove containers in one command:
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:
Step 2: Start the Containers
Navigate to the directory containing your docker-compose.yml
file and run:
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:
Step 4: Stop and Remove Containers
To stop the running containers:
This command stops and removes all containers defined in the docker-compose.yml
file.
Step 5: View Logs
To view logs of your services:
You can specify a service to view only its logs, for example:
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.