Home > database >  Docker cannot connect to daemon set after running docker restart
Docker cannot connect to daemon set after running docker restart

Time:06-23

I have a bash script that is running on an ec2 instance.It is running periodically,now the issue is that whenever in the script i run sudo service docker start it runs but after that when i run docker ps it gives me this error ERROR: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

Now while i have run the command in the script to provide permissions to run docker without sudo but whenever i restart it it seems to rewrite all the configurations.

echo "Installing Docker..."
sudo yum install -y docker
#sudo groupadd docker
#sudo usermod -aG docker ${USER}
tries=3
interval=15s
while [ $tries -gt 0 ]
do
        #sudo yum reinstall -y docker
        #sudo service docker start
        sudo groupadd docker
        sudo chmod 777 /var/run/docker.sock
        sudo usermod -aG docker ${USER}
        sudo service docker start
        sudo chkconfig docker on
        docker --version
        sudo service docker restart
        #sudo service docker start
        docker info && break
        let "tries--" && sleep $interval
done
docker info || exit

It gives me this error

Stopping docker: [60G[[0;32m  OK  [0;39m]

Starting docker:    .[60G[[0;32m  OK  [0;39m]

Client:
 Context:    default
 Debug Mode: false

Server:
ERROR: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http:///var/run/docker.sock/v1.24/info": dial unix /var/run/docker.sock: connect: permission denied
errors pretty printing info

is there any way to run docker without sudo even after running the restart command. Keep in mind that i cannot remove the restart command

CodePudding user response:

You can try this instead sudo chmod 666 /var/run/docker.sock

  • Related