How to Install Docker on Amazon Linux 2023 (EC2)
To install Docker on Amazon Linux 2023, connect to the EC2 instance and run sudo yum install docker -y, then sudo service docker start and sudo systemctl enable docker. Add your user to the docker group with sudo usermod -aG docker ec2-user, log out and back in, and test with docker run hello-world. To serve a web page from a container, run docker run -d -p 80:80 nginx and allow HTTP port 80 in the security group.
Come on, friends! Today we install Docker on EC2. Docker packs your app and everything it needs into one box – a container. If it runs on your laptop, it runs the same way on the server. So the very first job is to install Docker, then verify that it has started, and finally run our first container. Don't worry, it is really simple.
चला मित्रांनो! आज आपण EC2 वर Docker इन्स्टॉल करणार आहोत. Docker म्हणजे तुमचं ॲप आणि त्याला लागणाऱ्या सगळ्या गोष्टी एकाच डब्यात – कंटेनर. लॅपटॉप वर चाललं तर सर्व्हर वर पण तसंच चालतं. तो सबसे पहला काम है Docker इन्स्टॉल करना, मग स्टार्ट हुआ है या नहीं व्हेरिफाय करायचं, आणि शेवटी पहिला कंटेनर चालवायचा. घाबरू नका, एकदम सिंपल आहे.
चलो दोस्तों! आज हम EC2 पर Docker इंस्टॉल करेंगे. Docker मतलब आपका ऐप और उसे लगने वाली सारी चीज़ें एक ही डिब्बे में – कंटेनर. लैपटॉप पर चला तो सर्वर पर भी वैसे ही चलता है. तो सबसे पहला काम है Docker इंस्टॉल करना, फिर स्टार्ट हुआ है या नहीं वेरिफाय करना है, और आख़िर में पहला कंटेनर चलाना है. घबराओ मत, एकदम सिंपल है.
Quick answer
On an Amazon Linux 2023 EC2 instance, run these commands, then log out and SSH in again so the group change applies:
sudo yum install docker -y
sudo service docker start
sudo systemctl enable docker
sudo usermod -aG docker ec2-user # then exit and SSH in again
docker run hello-world # expect "Hello from Docker!"
What do I need before installing Docker?
- An EC2 instance running Amazon Linux 2023 with a public IP. New to this? Follow How to Launch an EC2 Instance in AWS.
- An SSH session as
ec2-user. See How to SSH into EC2 from Windows, Mac and Linux. - A free-tier eligible
t3.microort2.microis enough for learning. Docker images need disk space, so keep an eye ondf -h.
What happens when I run a container on EC2?
docker run pulls an image (read-only package) from Docker Hub and starts a container (running copy) on EC2. A request on port 80 passes the security group to the container.
An image is a read-only package (for example the official nginx image). A container is a running copy of that image. Docker pulls images from Docker Hub the first time you use them and keeps them on the instance.
How do I install Docker on Amazon Linux 2023?
Step 1 — Update the packages and install Docker
Amazon Linux 2023 has its own docker package in the default repository, so no extra repository is needed:
sudo yum update -y
sudo yum install docker -y
docker --version
Step 2 — Start Docker and enable it at boot
Docker does not start by itself after install. Start it now and enable it for every reboot, then check that it is running:
sudo service docker start
sudo systemctl enable docker
sudo service docker status # look for "active (running)"
sudo service works on Amazon Linux 2023 and hands over to systemctl, the modern equivalent (sudo systemctl start docker does the same).
Step 3 — Use Docker without sudo
The Docker daemon listens on a socket that only root and members of the docker group can use. Add ec2-user to that group:
sudo usermod -aG docker ec2-user
exit # log out, then SSH in again
groups # the list must now contain "docker"
Membership in the docker group is as powerful as sudo, so add only trusted users.
Ravindra Bagale's Tip
Many students run usermod and immediately run docker ps – and get "permission denied". A group change applies only to a new login. Run exit, SSH in again, and check that docker appears in groups. Pay attention: the docker group is almost root power – give it only to users you trust.
Ravindra Bagale's Tip – मराठी
खूप स्टुडंट्स usermod चालवतात आणि लगेच docker ps चालवतात – आणि "permission denied" येतो. ग्रुपचा बदल फक्त नवीन लॉगिनला लागू होतो. exit करा, पुन्हा SSH करा, आणि groups मध्ये docker दिसतो का ते बघा. लक्ष द्या: docker ग्रुप म्हणजे जवळपास root ची पॉवर – फक्त विश्वासाच्या यूजर्सना द्या.
Ravindra Bagale's Tip – हिंदी
बहुत स्टूडेंट्स usermod चलाते हैं और तुरंत docker ps चलाते हैं – और "permission denied" आता है. ग्रुप का बदलाव सिर्फ़ नए लॉगिन पर लागू होता है. exit करो, फिर से SSH करो, और groups में docker दिखता है या नहीं देखो. ध्यान दो: docker ग्रुप मतलब लगभग root की पावर – सिर्फ़ भरोसेमंद यूज़र्स को दो.
Step 4 — Run your first container
docker run hello-world # downloads a tiny test image and prints "Hello from Docker!"
docker ps -a # lists all containers, including stopped ones
docker images # lists the images on this instance
Step 5 — Run a web server in a container
Run the official Nginx image in the background (-d), map port 80 of the instance to port 80 of the container (-p host:container), and give it a name:
docker run -d -p 80:80 --name web --restart unless-stopped nginx
docker ps # STATUS "Up", PORTS 0.0.0.0:80->80/tcp
curl -I http://localhost # expect HTTP/1.1 200 OK
Allow HTTP (TCP 80) in the instance's security group (How to Open Port 80 and 443 in an EC2 Security Group) and open http://<PUBLIC_IP> — note http, not https. You see the Nginx welcome page, served from inside the container. 🐳
If Nginx or Apache is already installed on the instance itself, port 80 is taken. Stop it (sudo service nginx stop) or map another host port, for example -p 8080:80, and allow 8080 from My IP only.
Step 6 — Everyday Docker commands
docker logs web # output of the container
docker exec -it web bash # open a shell inside the container (type exit to leave)
docker stop web && docker start web # stop and start again
docker rm -f web # remove the container
docker image prune # delete unused images to free disk space
Step 7 — Optional: install the Docker Compose plugin
The Compose plugin is not in the Amazon Linux 2023 repository. Install it from the official Docker Compose releases on GitHub:
sudo mkdir -p /usr/local/lib/docker/cli-plugins
sudo curl -SL "https://github.com/docker/compose/releases/latest/download/docker-compose-linux-$(uname -m)" \
-o /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
docker compose version
Ravindra Bagale's Tip
The container is running but the page does not open in the browser? First run curl -I http://localhost on the server itself. If you get 200 here, Docker is fine – the problem is in the security group. And if you forget -p 80:80, the container runs inside but nobody outside can see it. Got it? The security group is a wall of fire – a request gets in only if the gate (port) is open.
Ravindra Bagale's Tip – मराठी
कंटेनर चालू आहे पण ब्राउझर मध्ये पेज येत नाही? आधी सर्व्हर वरच curl -I http://localhost चालवा. इथे 200 आलं तर Docker बरोबर आहे – प्रॉब्लेम सिक्युरिटी ग्रुप मध्ये आहे. आणि -p 80:80 विसरलं तर कंटेनर आत चालतो पण बाहेर कोणालाच दिसत नाही. समजलं का? सिक्युरिटी ग्रुप म्हणजे आग लागलेली भिंत आहे – गेट (पोर्ट) उघडलं तरच रिक्वेस्ट आत येते.
Ravindra Bagale's Tip – हिंदी
कंटेनर चल रहा है पर ब्राउज़र में पेज नहीं आ रहा? पहले सर्वर पर ही curl -I http://localhost चलाओ. यहाँ 200 आया तो Docker ठीक है – प्रॉब्लम सिक्योरिटी ग्रुप में है. और -p 80:80 भूल गए तो कंटेनर अंदर चलता है पर बाहर किसी को दिखता नहीं. समझ आया? सिक्योरिटी ग्रुप मतलब आग लगी दीवार – गेट (पोर्ट) खुला हो तभी रिक्वेस्ट अंदर आती है.
How do I fix common Docker errors on EC2?
Ghabru naka 😅 — these are the ones everybody meets:
| Symptom | Likely cause | Fix |
|---|---|---|
permission denied while trying to connect to the Docker daemon socket |
User not in the docker group, or no new login yet |
sudo usermod -aG docker ec2-user, exit, SSH in again, groups |
Cannot connect to the Docker daemon ... Is the docker daemon running? |
Docker service stopped | sudo service docker start; sudo systemctl enable docker |
bind: address already in use on port 80 |
Nginx/Apache on the host already uses port 80 | sudo ss -tlnp | grep :80; stop it, or use -p 8080:80 |
Browser timeout, curl localhost works |
Port missing in the security group; typed https:// |
Add inbound HTTP 80 (or your port); use http:// |
docker compose is not a docker command |
Compose plugin not installed | Step 7 |
no space left on device |
Old images and stopped containers | docker system df; docker image prune; grow the EBS volume |
Learn it properly
This guide is the short path. These free lessons explain the Linux and networking basics behind it:
Samajla ka? Got it? Install, start, enable, the docker group, and log in again – that's all. Now you can run any app in a minute with docker run. You will get it, slowly you will get it – run one new image every day.
समजलं का? Install, start, enable, docker ग्रुप, आणि पुन्हा लॉगिन – एवढंच. आता docker run ने कोणतंही ॲप एका मिनिटात चालवू शकता. कळेल तुम्हाला, हळू हळू कळेल – रोज एक नवीन इमेज चालवून बघा.
समझ आया? Install, start, enable, docker ग्रुप, और फिर से लॉगिन – बस इतना ही. अब docker run से कोई भी ऐप एक मिनट में चला सकते हो. धीरे धीरे समझ में आएगा – रोज़ एक नई इमेज चलाकर देखो.
Frequently asked questions
How do I install Docker on Amazon Linux 2023?
Run sudo yum install docker -y, then sudo service docker start and sudo systemctl enable docker. Add your user to the docker group with sudo usermod -aG docker ec2-user and log in again.
Why do I get "permission denied while trying to connect to the Docker daemon socket"?
Your user is not in the docker group yet, or you did not log in again after adding it. Run sudo usermod -aG docker ec2-user, exit the SSH session, connect again and check with groups.
Is Docker the same as docker-ce on Amazon Linux 2023?
Amazon Linux 2023 ships its own docker package in the default repository, so you do not need the docker-ce repository. The commands (docker run, docker ps, docker images) are the same.
How do I install Docker Compose on Amazon Linux 2023?
The Compose plugin is not in the Amazon Linux 2023 repository. Download the docker-compose binary from the official Docker Compose GitHub releases into /usr/local/lib/docker/cli-plugins/, make it executable and check with docker compose version.
Why does my container page not open in the browser?
Usually the security group does not allow the host port, the -p host:container mapping is missing or wrong, or another program (Nginx or Apache on the host) already uses that port. Check with docker ps and sudo ss -tlnp.
Does Docker start again after a reboot?
Only if you enabled it: sudo systemctl enable docker. Containers restart too if you start them with --restart unless-stopped.