r/Ubuntu • • 1d ago

Docker Error Help

Hello I am unsure if this is the right place to post this but I am in need of assistance from someone much more knowledgeable than myself. I need to install and use docker through version 26.10 Ubuntu on VirtualBox for a lab I am currently doing in school. I found the install docker engine guide online and I am getting it all setup so I can run this code:

docker run --rm --network none alpine:3.21 sh -c \

'echo "container hostname: $(hostname)"; \

echo "container shell PID: $$"; \

echo "container PID 1: $(cat /proc/1/comm)"; \

echo "container kernel: $(uname -r)"; \

echo "container PID namespace: $(readlink /proc/self/ns/pid)"'

permission denied while trying to connect to the docker API at unix:///var/run/docker.sock

Anytime I run this I am having the following error:

permission denied while trying to connect to the docker API at unix:///var/run/docker.sock

I know this can be fixed by editing groups or using sudo but my lab explicitly states to use neither of these for safety reasons. I have tried researching online with not much luck except for rootlesskit which requires --force which is also a no go. If anyone has any ideas I would appreciate it.

3 Upvotes

4 comments sorted by

1

u/PokemonCueballAgain 1d ago

you're hitting the classic docker socket permissions wall, it's not your setup it's just that docker by default only lets root or users in the `docker` group talk to that socket

since sudo and group edits are off limits, rootless docker is probably your only path here but the fact your lab says no to `--force` too is rough, usually you need that for the systemd setup or to override some checks

maybe check if your instructor intended for you to use podman instead? it's daemonless and plays nicer with user permissions out of the box, a lot of docker commands just work if you alias it

1

u/Only-Stable3973 19h ago

Are you sure you can't add your user to docker group to run commands without sudo, usermod -aG docker $USER, it is a normal part of installing docker and docker compose.

1

u/gmes78 16h ago

You can probably use podman instead of docker here. It can run unprivileged containers just fine.

1

u/DismalFee7 10h ago

You shouldn't be using docker, use podman.