Search code examples
linuxdockerdocker-composedebiandocker-desktop

docker-compose stop working after Docker Desktop installation on Debian 11


I installed Docker Desktop for Linux on my Debian 11 machine.

After the installation, I'm not able to use docker-compose or laravel sail. The error is:

ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

The DOCKER_HOST env variable is not set.

The docker CLI is still working properly.

Someone can help me? Thanks in advance


Solution

  • EDIT:

    Fastest and cleaner way:

    Check "Enable Docker Compose V1/V2 compatibility mode" in the General section of the Docker Desktop settings.

    TLDR:

    1. Run the command docker context ls to discover the new host.

    2. Copy the DOCKER ENDPOINT corresponding to the desktop-Linux context

    3. Set the DOCKER_HOST environment variable by choosing one of those two methods:

      • Open a terminal and execute export DOCKER_HOST={your docker endpoint} (this is valid only for the current terminal session and you will lose the config on system reboot)
      • Follow those instructions to set a permanent environment variable (you have to use DOCKER_HOST as a variable name and your own DOCKER ENDPOINT as a value, not the ones used as an example in the answer)

    Long answer and explanation:

    The Docker Desktop on Linux runs on a virtual machine and uses docker compose V2 instead of docker-compose (the command to use it is docker compose without the hyphen).

    To avoid it masks the docker engine service on the local machine and creates a new context.

    As the local Docker service has been masked, it is not running anymore on your local machine.

    The context can be switched to the default one if you want to use Docker Engine instead of Docker Desktop. That way your local docker-compose will work as before.

    Another way is to connect the local docker-compose to the Docker Desktop host on the new virtual machine.

    This can be done in two ways:

    1. By using an environment variable, as explained above in the TLDR section.
    2. By passing the host address to the docker-compose command: docker-compose -H {your docker endpoint} COMMAND