Installing Docker Made Easy
Welcome back to Day 2 of our Docker journey! previously, we explored the world of containers and why Docker is revolutionising development. If you missed it, catch up here Day 1 – trust me, it’s worth it.
Now that you understand why Docker is essential, it's time to get practical. We’re going to set up Docker on your system. I get it going through official documentation can sometimes feel overwhelming. But don’t worry, I’ve got a quick, no-fuss solution for you!
Docker Installation in a Snap
You could head over to the official Docker documentation and follow the steps based on your operating system. Or, if you're like most of us and want to skip the hassle, I’ve got a handy script that will install Docker and Docker Compose for you in one go. 🛠️
Here’s all you need to do:
#!/bin/bash
sudo apt update -y && sudo apt upgrade -y
sudo apt-get install -y ca-certificates curl jq docker.io
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
COMPOSE_VERSION=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | jq -r .tag_name)
sudo curl -L "https://github.com/docker/compose/releases/download/$COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo docker run hello-world
docker --version
docker-compose --version
echo "Please restart the system to apply Docker group permission"
How to Run It:
Copy the script above.
Paste it into a new file on your terminal (e.g.,
docker-install.sh
).Grant execution permissions by running:
chmod +x docker-install.sh
Run the script:
./docker-install.sh
That’s it! Let the script handle the hard work while you grab a cup of coffee. ☕ It will take care of everything: updating your system, installing Docker and Docker Compose, setting permissions, and running the classic hello-world Docker container as a test.
What’s Going On Here?
To keep things transparent, let’s break down what the script does:
System Update & Upgrade: Ensures your system is up-to-date.
Docker Installation: Installs Docker and dependencies.
Enable Docker Service: Automatically starts Docker every time your system boots.
User Permissions: Adds you to the Docker group to avoid needing
sudo
with every command.Docker Compose Installation: Downloads and installs the latest version of Docker Compose.
Testing: Runs
hello-world
to verify everything works.docker run hello-world
Simple, right? Now, you’re all set with Docker on your machine. 🎉
Running Docker on AWS EC2 Ubuntu:
But what if you're using AWS EC2? No problem. You can run the exact same script on an EC2 instance to install Docker. It’s efficient and quick, giving you a fully configured Docker setup in minutes. To deploy on an AWS EC2 instance:
SSH into your EC2 instance.
Run the script just as you would on your local machine.
If you need detailed steps on setting up an EC2 instance, you can find them in the AWS documentation, but rest assured, this script will handle Docker setup seamlessly.
Note: This script is designed to work on Debian-based systems like Ubuntu. If you're using a different operating system, please refer to the official Docker documentation for the appropriate installation steps.
Want to Try Docker without Installing?
No installation, no problem! If you’re not ready to install Docker locally just yet, check out Docker’s official playground: Play with Docker. Here, you can practice in a pre-configured environment without needing to install a thing. It’s perfect for testing commands and getting a feel for Docker.
After logging into the Docker Playground, you'll see an "ADD NEW INSTANCE" option on the left-side menu. Click on it, and a terminal will open where you can start working right away—no installation needed. It's a convenient alternative to setting up Docker.
Pro tip:
When using the playground, use Ctrl + Shift + V
to paste commands into the terminal. The sessions are temporary, but it’s a great way to get hands-on quickly.
Wrapping Up
Today, we’ve covered everything you need to get Docker up and running, whether on your local machine or in the cloud. Next time, we’ll dive into Docker commands and understand key concepts like containers, images, and more. Stay tuned, and don’t forget to subscribe so you don’t miss a thing!