Last Updated: 2022-05-26
On a production server, when I ran:
$ docker-compose down
It executed this command but subsequently failed because it needed more
permissions. So, as per the usual protocol, I tried again with
$ sudo docker-compose down
But now I got the error: "sudo: docker-compose: command not found" Why?
The reason is that when you sudo, you get a pre-configured
$PATH, which is
(supposed to be) something like the root user's default path. Having not
specified this, my
docker-compose program was not in that list of directories
given by this
$ sudo /usr/local/bin/docker-compose down
This is docker specific, but theoretically you could design your API in the same way
Create a unix group called
docker and add your user to it.
# create the group sudo groupadd docker # add the current user to it sudo usermod -aG docker $USER # Log in and out to ensure this works
Thus, even though the docker daemon runs as
root, it makes this socket
read/writable by the
docker group, allowing non-root users to communicate with
sudo. Nifty, huh?