I have a bash script file (startKms) that starts a docker container. The details of the script is at the end of this question. The startKms file is located at $HOME/myscripts and a soft link added to $HOME/bin so that the command can be executed from any location. When I execute startKms or sudo startKms the shell says command not found. However if I place the soft link under /usr/local/sbin and execute sudo starKms then the script works fine. If I execute without sudo then I get the below error message.
"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.40/containers/json?filters=%7B%22name%22%3A%7B%22kms%22%3Atrue%7D%7D: dial unix /var/run/docker.sock: connect: permission denied Starting Kurento Media Server on Docker .... Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/kms/start: dial unix /var/run/docker.sock: connect: permission denied Error: failed to start containers: kms"
which docker points to /usr/bin/docker $PATH contains all three locations 1. $HOME/bin 2. /usr/local/sbin and 3. /usr/bin
- Why is my command not being found when file is placed under $HOME/bin though $PATH has this location?
- Why is my command working fine when placed under /usr/local/sbin and run as sudo?
- Why am I getting above error message related to permissions?
I have NOT made settings to use Docker as non-root user, i.e adding user to docker group as suggested here installing docker I am a newbie to Linux and installed Ubuntu in my laptop. No changes made to .bashrc .profile etc
#!/bin/bash
if [ ! "$(docker ps -qf name=kms)" ];then
echo "Starting Kurento Media Server on Docker ...."
docker start kms
exit 1
fi
echo -e "\e[1;31mKurento Media Server is already running\e[0m"
0 Answers