Skip to main content
Most Docker errors on a server have a one-line fix. Permission denied on docker.sock means your user isn’t in the docker group: run sudo usermod -aG docker $USER and log in again. Port is already allocated means another container publishes that host port: find it with docker ps --filter publish=8080 and stop it or change the port. Cannot connect to the Docker daemon means Docker isn’t running: start it with sudo systemctl start docker.

Before you start

  • Copy the exact error line. The fixes below match on the wording.
  • Check what Docker is doing with sudo systemctl status docker and sudo journalctl -u docker -n 50 --no-pager. See read logs with journalctl.

Permission denied while trying to connect to the docker API

Older Docker versions say ...to connect to the Docker daemon socket at unix:///var/run/docker.sock. Either way, your user can’t use the Docker socket.
1

Add your user to the docker group

2

Log out and back in

Group changes apply to new logins. Close the SSH session and connect again, or run newgrp docker in the current one.
3

Test

The docker group gives root-level control of the server. Don’t fix this with chmod 666 /var/run/docker.sock, which gives that control to every user and process. See secure Docker on a VPS.
If you then see WARNING: Error loading config file: /home/alex/.docker/config.json - ... permission denied, you ran docker with sudo before. Fix the folder’s owner with sudo chown "$USER":"$USER" ~/.docker -R.

Cannot connect to the Docker daemon

Docker 29 can also say failed to connect to the docker API at unix:///var/run/docker.sock; check if the path is correct and if the daemon is running.
1

Start Docker and enable it at boot

2

If it won't start, check daemon.json

A typo in /etc/docker/daemon.json stops the daemon. Test the file:
A good file prints configuration OK. A broken one names the problem, for example invalid JSON: invalid character '}' looking for beginning of object key string (a trailing comma) or the following directives don't match any configuration option.
3

Check DOCKER_HOST

If this prints a value you didn’t set on purpose, clear it with unset DOCKER_HOST and remove it from ~/.bashrc.
If the disk is full, Docker can fail to start too. Check with df -h and see fix “No space left on device”.

Bind for 0.0.0.0:8080 failed: port is already allocated

Another container already publishes that host port. Find it:
Stop or remove that container (docker stop web1), or publish yours on a free port, such as "8081:80".

failed to bind host port: address already in use

A program on the server, not a container, uses the port. This is common with ports 80 and 443 when Nginx or Apache is installed. Find it:
The users: column names the process. Stop and disable it (for example sudo systemctl disable --now nginx) or choose another port. See check open ports on Linux.

The container name is already in use

An old container with that name still exists, often stopped. Remove it with docker rm web1 (or docker rm -f web1 if it’s running), then run your command again. Data in volumes is kept.

exec: “bash”: executable file not found in $PATH

The image doesn’t contain that program. Small images such as Alpine have sh but not bash. Use docker exec -it web1 sh.

Other errors you might see

Frequently asked questions

Why does my container keep restarting?

The app inside exits with an error and the restart policy starts it again. Read the reason with docker logs --tail 50 <name>. Missing environment variables and wrong file permissions on bind mounts are the usual causes.

Why can’t I reach my container from the internet?

Check that the port is published on 0.0.0.0 (docker ps), that the app inside listens on 0.0.0.0 and not 127.0.0.1, and test from outside with check if a port is open.

Why is my container reachable even though UFW blocks the port?

Docker-published ports bypass UFW. See secure Docker on a VPS.

VPS and dedicated server guides

Every guide in this section.

Docker commands cheat sheet

ps, logs, exec and more.

Install Docker

Reinstall Docker the official way.

Secure Docker on a VPS

The docker group, ports and firewalls.

Clean up Docker disk space

Free space Docker is using.

Checked against the official Docker daemon troubleshooting guide, Linux post-installation steps and Docker Hub pull limits on 4 November 2026; the permission, daemon connection, port, name conflict, executable and daemon.json errors were reproduced on Ubuntu 24.04 LTS with Docker Engine 29.9.2. Wording can differ in other Docker releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026