First Mistake As A Sysadmin
Welcome to our blog post where we discuss a common mistake made by new sysadmins and DevOps engineers - installing Docker without understanding the networking configuration. This post is designed.
# First Mistake As A Sysadmin: Installing Docker Without Understanding Networking Configuration
Welcome to our blog post where we discuss a common mistake made by new sysadmins and DevOps engineers - installing Docker without understanding the networking configuration. This post is designed for experienced system administrators, focusing on practical implementation of self-hosted infrastructure solutions in your homelab or production environment.
Prerequisites
- Ubuntu 20.04 LTS (Focal Fossa) or CentOS 8 Stream (exact versions may vary depending on Docker version)
- Docker CE version 5.0.8 or higher (Download Docker Community Edition)
Solution
Step 1: Install Docker Engine
Install the required package using the following command:
1
2
3
apt-get update && apt-get install -y docker-ce=5.0.8 \
docker-ce-cli=5.0.8 \
containerd.io
For CentOS, use:
1
yum install -y docker-ce-19.03.12 docker-ce-clicli
Step 2: Configure Docker Networking
By default, Docker creates a NAT network for your containers. However, if you want to use host networking or custom networks, you’ll need to configure Docker networking properly. Here is an example of how to create a custom bridge network:
1
2
3
4
5
6
7
8
9
10
11
cat << EOF | sudo tee /etc/docker/daemon.json
{
"fixed-cidr": "10.244.0.0/16",
"iptables": false,
"log-driver": "journald",
"log-opts": {
"max-size": "10m"
},
"storage-opt": {"storage-driver": "overlay2"}
}
EOF
Now reload Docker daemon:
1
2
sudo systemctl daemon-reload
sudo systemctl restart docker
Step 3: Create and Start a Container
Create a simple Nginx container using the following command:
1
2
3
4
docker run -d --name mynginx \
-p 80:80 \
-v /path/to/mynginx.conf:/etc/nginx/conf.d/default.conf \
nginx
Step 4: Verify the Setup
Verify that your container is running and exposed on port 80 using the following command:
1
docker ps
Troubleshooting
If you encounter issues with Docker, check the logs using journalctl -u docker
. Also, ensure that your firewall is configured to allow incoming traffic on port 80.
Conclusion
Understanding Docker networking configuration is crucial for a smooth operation of your containers in self-hosted environments. This post provided you with an example setup and step-by-step instructions for creating and configuring custom networks in Docker. Always remember to test your applications thoroughly and keep your infrastructure secure by updating packages regularly, using best security practices, and monitoring your environment.
For more information about Docker, visit the Docker documentation. Happy sysadminning!