> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Fix Common Docker Errors (docker.sock, Port Allocated)

> Fix common Docker errors: permission denied on docker.sock, cannot connect to the Docker daemon, port is already allocated, and address already in use.

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`.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 5–15 minutes | Any Linux server with Docker Engine | SSH access with sudo |

## 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](https://help.freakhosting.com/portals/other/how-to-read-logs-with-journalctl.md).

## Permission denied while trying to connect to the docker API

```text theme={null}
permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
```

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**

```bash theme={null}
sudo usermod -aG docker $USER
```

**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**

```bash theme={null}
docker ps
```

> [!WARNING]
>
> 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](https://help.freakhosting.com/portals/other/how-to-secure-docker-on-a-vps.md).

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

```text theme={null}
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
```

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**

```bash theme={null}
sudo systemctl enable --now docker
```

**2. If it won't start, check daemon.json**

A typo in `/etc/docker/daemon.json` stops the daemon. Test the file:

```bash theme={null}
sudo dockerd --validate --config-file /etc/docker/daemon.json
```

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**

```bash theme={null}
env | grep 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"](https://help.freakhosting.com/portals/other/how-to-fix-no-space-left-on-device.md).

## Bind for 0.0.0.0:8080 failed: port is already allocated

```text theme={null}
Error response from daemon: failed to set up container networking: driver failed programming external connectivity on endpoint web2 (...): Bind for 0.0.0.0:8080 failed: port is already allocated
```

Another **container** already publishes that host port. Find it:

```bash theme={null}
docker ps --filter publish=8080 --format '{{.Names}}\t{{.Ports}}'
```

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

```text theme={null}
failed to bind host port 0.0.0.0:80/tcp: 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:

```bash theme={null}
sudo ss -ltnp 'sport = :80'
```

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](https://help.freakhosting.com/portals/other/how-to-check-open-ports-on-linux.md).

## The container name is already in use

```text theme={null}
Conflict. The container name "/web1" is already in use by container "6028c847...". You have to remove (or rename) that container to be able to reuse that name.
```

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

```text theme={null}
OCI runtime create failed: runc create failed: unable to start container process: error during container init: 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

| Error | Cause | Fix |
| - | - | - |
| `You have reached your pull rate limit` | Docker Hub allows 100 pulls per 6 hours per IPv4 address (or IPv6 /64) without logging in | Wait, or run `docker login` with a Docker account (200 pulls per 6 hours on a free account) |
| `exec format error` | The image was built for another CPU type, such as arm64 on an amd64 server | Compare `uname -m` with `docker image inspect <image> --format '{{.Architecture}}'` and use a matching image |
| `docker: unknown command: docker compose` | The Compose plugin isn't installed | `sudo apt install docker-compose-plugin` or `sudo dnf install docker-compose-plugin` |
| `the attribute 'version' is obsolete` | A warning, not an error | Delete the `version:` line from `compose.yaml` |
| `no space left on device` | The disk or Docker's data folder is full | [Clean up Docker disk space](https://help.freakhosting.com/portals/other/how-to-clean-up-docker-disk-space.md) |

## 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](https://help.freakhosting.com/portals/other/how-to-check-if-a-port-is-open-from-outside.md).

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

Docker-published ports bypass UFW. See [secure Docker on a VPS](https://help.freakhosting.com/portals/other/how-to-secure-docker-on-a-vps.md).

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [Docker commands cheat sheet](https://help.freakhosting.com/portals/other/essential-docker-commands.md)
>
> ps, logs, exec and more.

> [card] [Install Docker](https://help.freakhosting.com/portals/other/how-to-install-docker.md)
>
> Reinstall Docker the official way.

> [card] [Secure Docker on a VPS](https://help.freakhosting.com/portals/other/how-to-secure-docker-on-a-vps.md)
>
> The docker group, ports and firewalls.

> [card] [Clean up Docker disk space](https://help.freakhosting.com/portals/other/how-to-clean-up-docker-disk-space.md)
>
> Free space Docker is using.

***

> [!NOTE]
>
> **Checked against the official [Docker daemon troubleshooting guide](https://docs.docker.com/engine/daemon/troubleshoot/), [Linux post-installation steps](https://docs.docker.com/engine/install/linux-postinstall/) and [Docker Hub pull limits](https://docs.docker.com/docker-hub/usage/pulls/)** 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.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.