Table of contents
- Step 1: Accessing Your AWS EC2 Instance:
- Step 2: Setting Up SSH Access to the EC2 Instance:
- Step 3: Connecting to Your EC2 Instance:
- Step 4: Checking Docker Installation:
- Step 5: Creating a New User:
- Step 6: Adding the User to the Docker Group:
- Step 7: Verifying the User's Group Membership:
- Step 8: Testing Docker Access:
Introduction: Docker and AWS EC2 are popular tools in modern cloud computing. This guide will walk you through adding an average user to the Docker group on an AWS EC2 instance, allowing them to run Docker commands without needing root access.
Step 1: Accessing Your AWS EC2 Instance:
Log in to the AWS Management Console.
Navigate to the EC2 dashboard.
Select the desired EC2 instance you want to work with.
Step 2: Setting Up SSH Access to the EC2 Instance:
If you haven't already, create an SSH key pair using the
ssh-keygen
command on your local machine.Launch your EC2 instance with the SSH key pair attached.
Step 3: Connecting to Your EC2 Instance:
Use the
ssh
command to connect to your EC2 instance. Replace<your-ec2-instance-ip>
with your instance's public IP address and<your-private-key.pem>
with your private key file:ssh -i <your-private-key.pem> ec2-user@<your-ec2-instance-ip>
Step 4: Checking Docker Installation:
Verify if Docker is already installed by running:
docker --version
If Docker is not installed, follow the Docker installation guide for your Linux distribution.
Step 5: Creating a New User:
Create a new user using the
adduser
command. Replace<new-username>
with your desired username:sudo adduser <new-username>
Follow the prompts to set a password and other user details.
Step 6: Adding the User to the Docker Group:
Add the newly created user to the Docker group using the
usermod
command:sudo usermod -aG docker <new-username>
Step 7: Verifying the User's Group Membership:
To confirm that the user is now a member of the Docker group, run:
groups <new-username>
The output should include "docker" among the user's groups.
Step 8: Testing Docker Access:
Log out of your EC2 instance and log back in as the new user:
bashCopy codeexit ssh -i <your-private-key.pem> <new-username>@<your-ec2-instance-ip>
Test Docker access by running a Docker command without
sudo
, for example:docker ps
Conclusion: By following these steps, you have successfully added an average user to the Docker group on your AWS EC2 instance. This allows them to utilize Docker for their development and deployment needs while maintaining a secure environment.