Restart docker from within - Is the docker daemon running?

Hi, I’m trying to send a command in the terminal of one of my containers “my_container”:

sudo docker restart my_container 

at first I got: bash: docker: command not found
So I installed a docker but now I keep getting these permission denied errors

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

or

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

I’ve tried the solutions in here but to no success docker command not found even though installed with apt-get
Adding a screenshot of the commands


Thank you for your help

Hi,

can you detail your scenario?
In which terminal are you trying? From your desktop OS’s terminal or one on balenaCloud dashboard?
Did you ssh to the device? With balena-cli or other way?

You should be able to restart the container from the balenaCloud dashboard by clicking the :arrows_clockwise: circular arrows Restart button at the end of the row in the services section.
You can restart the container with the help of the supervisor: Interacting with the balena Supervisor - Balena Documentation

In case you want to use docker commands you need to be in a terminal on the Host OS where the docker command is replaced with the balena command. For example to list the running containers you may run balena ps instead of “docker ps”

Hi,
I’m trying from Balena terminal, and I want to be able to send a command to restart, not through the button, in the container I’m trying to restart

Hi,

calling the supervisor should work from the container you want to restart too.

You can restart the container with the help of the supervisor: Interacting with the balena Supervisor - Balena Documentation

But it is a bit tricky since you will lose connection until the container restarts, and then you need to reconnect.

If I understand you correctly, this should restart:

curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "my-service"}'
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"imageId": 1234}'

Which means it will only stop and start the container that I put the command in, and not do anything with the other containers?

Hi,

The following command is enough to restart the service since support for passing serviceName instead of imageId was added in supervisor v8.2.2:

curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "my-service"}'

This will only restart the service that you specified using serviceName. Note that you will also need to add the io.balena.features.supervisor-api label to the service in order to allow it to access the supervisor API.