DEV Community

SHUBHENDU SHUBHAM
SHUBHENDU SHUBHAM

Posted on

Resolving Docker Socket and Daemon Conflicts: Unifying CLI and Docker Desktop on kali Linux

If you're using Docker Desktop on Linux and facing issues like conflicting results between docker ps and sudo docker ps, containers not appearing in Docker Desktop, or volume permission errors, this detailed guide will walk you through resolving these problems. We'll cover everything you need to know to harmonize Docker CLI and Docker Desktop under a unified context (desktop-linux) while troubleshooting common issues.

docker ps

sudo docker ps

and you're getting different results. Then you're at the right place.

Understanding the Problem

1.Different Results for docker ps vs sudo docker ps:

  • When you run docker ps, you might see no containers, but sudo docker ps displays running containers.
  • This happens because docker and sudo docker may be pointing to different Docker socket files (DOCKER_HOST endpoints).

2.Containers Not Showing in Docker Desktop:

  • Even if sudo docker ps displays running containers, they might not appear in the Docker Desktop UI. This occurs when the Docker daemon's configuration or context is not aligned with Docker Desktop.

3.Root Causes:

  • DOCKER_HOST environment variable overriding the context.
  • Docker CLI using /var/run/docker.sock while Docker Desktop uses ~/.docker/desktop/docker.sock.
  • Misconfigured permissions on directories and files used in volume mappings.

Step-by-Step Troubleshooting

Step 1: Identify the Active Contexts

To diagnose the issue, check which Docker context is active and ensure it matches the expected configuration for Docker Desktop.

List Docker Contexts:

docker context ls

Enter fullscreen mode Exit fullscreen mode

eg output:

NAME TYPE DESCRIPTION DOCKER ENDPOINT
default * moby Current DOCKER_HOST-based configuration unix:///var/run/docker.sock
desktop-linux moby Docker Desktop unix:///home/user/.docker/desktop/docker.sock

The * indicates the active context. If default is active but you’re using Docker Desktop, you need to switch to desktop-linux

Step 2: Unset the DOCKER_HOST Environment Variable

When DOCKER_HOST is set, it overrides the active context. To fix this:

  • Check DOCKER_HOST:
echo $DOCKER_HOST

Enter fullscreen mode Exit fullscreen mode

If set (e.g., unix:///var/run/docker.sock), proceed to unset it.

  • Unset Temporarily:
unset DOCKER_HOST

Enter fullscreen mode Exit fullscreen mode
  • Remove Permanently: Edit your shell configuration file:
nano ~/.bashrc

Enter fullscreen mode Exit fullscreen mode
  • Remove or comment out any DOCKER_HOST line:
# export DOCKER_HOST=unix:///var/run/docker.sock

Enter fullscreen mode Exit fullscreen mode
  • Reload the shell:
source ~/.bashrc

Enter fullscreen mode Exit fullscreen mode

Step 3: Align Docker CLI with Docker Desktop

Ensure that the Docker CLI points to the desktop-linux context:

1.Set desktop-linux as Active Context:

docker context use desktop-linux

Enter fullscreen mode Exit fullscreen mode

2.Verify Context:

docker context ls

Enter fullscreen mode Exit fullscreen mode

Expected Output:

NAME TYPE DESCRIPTION DOCKER ENDPOINT
default moby Current DOCKER_HOST-based configuration unix:///var/run/docker.sock
desktop-linux * moby Docker Desktop unix:///home/user/.docker/desktop/docker.sock

Image description

Image description

3.Test docker ps: Run docker ps to confirm it now shows running containers managed by Docker Desktop

Step 4: Debug docker ps vs sudo docker ps

If docker ps and sudo docker ps still show different results, the issue lies with permission conflicts on the Docker socket file

1.Check Socket Permissions:

ls -l /var/run/docker.sock

Enter fullscreen mode Exit fullscreen mode

Example Output:
srw-rw---- 1 root docker 0 Mar 22 10:00 /var/run/docker.sock

2.Grant User Access to Docker Group:

  • Add your user to the Docker group:
sudo usermod -aG docker $USER

Enter fullscreen mode Exit fullscreen mode

Log out and log back in to apply the group change.

3.Re-test docker ps:

docker ps

Enter fullscreen mode Exit fullscreen mode

Image description

This should now show the same output as sudo docker ps.

Step 5: Resolve Missing Containers in Docker Desktop

If containers are visible in docker ps but not in Docker Desktop, verify and restart Docker Desktop services.

1.Restart Docker Desktop:

systemctl --user restart docker-desktop

Enter fullscreen mode Exit fullscreen mode

2.Check Status:

systemctl --user status docker-desktop

Enter fullscreen mode Exit fullscreen mode

3.Ensure Unified Context: Confirm docker ps aligns with Docker Desktop's context:

docker context ls

Enter fullscreen mode Exit fullscreen mode

Step 6: Test and Validate

Now, test your setup to ensure all components are working correctly:

1.Run a Test Container:

docker run --rm hello-world

Enter fullscreen mode Exit fullscreen mode

2.Inspect Running Containers:

docker ps

Enter fullscreen mode Exit fullscreen mode

3.Verify in Docker Desktop: Check the Docker Desktop UI to confirm the container is listed.

in my case I have directly spined wazuh docker single node

Image description

ENJOY DOCKER DESKTOP 🖥️ ON KALI MACHINE

Image description

Conclusion

By following these steps, you can unify Docker CLI and Docker Desktop on Linux, resolve docker ps vs sudo docker ps conflicts, and fix permission issues for a seamless development experience. With the desktop-linux context configured, Docker will run harmoniously across CLI and Docker Desktop.

Keep learning, keep Troubleshooting !

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️