I try install docker like this on EC2 amazon linux and I found this error
# Install Docker
sudo yum install -y docker
sudo systemctl enable docker
sudo systemctl start docker
sudo usermod -aG docker ec2-user
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.44/containers/json": dial unix /var/run/docker.sock: connect: permission denied
It can fix by control+C and ssh to instance again but I don’t want that method how can I completed one time in shellscript and make it can run without control+C and ssh again
2
Answers
It looks like you’re outlining the correct steps to install Docker on an Amazon EC2 instance running Amazon Linux. Here’s a concise summary of the process, including some clarifications:
Manual Installation Steps (If Not Using a Script)
You can also run the commands manually:
Remove existing Docker installation
sudo yum autoremove docker -y
Install Docker
sudo yum install docker -y
Start the Docker service
sudo service docker start
Add the ec2-user to the Docker group
sudo usermod -aG docker ec2-user
Enable Docker to start on boot
sudo systemctl enable docker
Check Docker version
docker –version
Important Note
After running the usermod command, you will need to log out of the EC2 instance and log back in for the group changes to take effect. This is crucial because it allows the ec2-user to run Docker commands without sudo.
What worked for me was :-
sudo chmod 777 /var/run/docker.sock
But before running the above command make sure the user is added in docker group
sudo usermod -a -G docker <Your_User_Name>