Cannot connect to the Docker daemon on bash on Ubuntu windows

前端 未结 7 1269
时光说笑
时光说笑 2021-01-30 12:53

I am able to install docker, docker-compose and docker-machine

However when I try to run

root@DESKTOP-51NFMIM:~# docker ps
Cannot connect to the Docker d         


        
相关标签:
7条回答
  • 2021-01-30 13:28

    The Docker client and server can now be installed and run purely in WSL without Docker Desktop for Windows if you are running Windows 10 version 1803 or greater. I have it working on the following WSL:

    OS: Ubuntu 18.04 bionic [Ubuntu on Windows 10]
    Kernel: x86_64 Linux 4.4.0-17763-Microsoft
    

    Simply follow the same instructions to install on Ubuntu but make sure to choose a specific version to install. Presently, version 18.06.1~ce~3-0~ubuntu works fine but later versions up to 5:18.09.6~3-0~ubuntu-bionic have an issue with starting up a container. The following command will install the latest working version:

    apt-get install docker-ce=18.06.1~ce~3-0~ubuntu
    

    To get the Docker server running in WSL after installation, close all open terminals and start a new Ubuntu terminal as administrator (i.e., right click the Ubuntu shortcut and click 'Run as administrator'). Finally, run the following commands:

    sudo cgroupfs-mount
    sudo service docker start
    

    sudo service docker start will have to be run each time Windows is rebooted. However, if you wish to avoid that, you can automate it using the Task Scheduler and a shell script by following the steps listed here.

    Test that everything is working using:

    docker run hello-world
    

    Reference: https://medium.com/faun/docker-running-seamlessly-in-windows-subsystem-linux-6ef8412377aa

    0 讨论(0)
  • 2021-01-30 13:35

    Found the solution on this post: https://blog.jayway.com/2017/04/19/running-docker-on-bash-on-windows/

    Running docker against an engine on a different machine is actually quite easy, as Docker can expose a TCP endpoint which the CLI can attach to.

    This TCP endpoint is turned off by default; to activate it, right-click the Docker icon in your taskbar and choose Settings, and tick the box next to “Expose daemon on tcp://localhost:2375 without TLS”.

    With that done, all we need to do is instruct the CLI under Bash to connect to the engine running under Windows instead of to the non-existing engine running under Bash, like this:

    $ docker -H tcp://0.0.0.0:2375 images
    

    There are two ways to make this permanent – either add an alias for the above command or export an environment variable which instructs Docker where to find the host engine (NOTE: make sure to use single apostrophe's below):

    $ echo "export DOCKER_HOST='tcp://0.0.0.0:2375'" >> ~/.bashrc
    $ source ~/.bashrc
    

    Now, running docker commands from Bash works just like they’re supposed to.

    $ docker run hello-world
    

    Successful response:

    Hello from Docker!This message shows that your installation appears to be working correctly.
    
    0 讨论(0)
  • 2021-01-30 13:38

    If you are using docker desktop for windows (and do not require TLS for the connection) then go to the docker desktop setting, general section and enabled the checkbox "Expose daemon on tcp://localhost:2375 without TLS".

    Update: in newer Docker desktop versions the WSL integration has moved to the resources section.

    0 讨论(0)
  • 2021-01-30 13:39

    only needs add a env variable in your system

    0 讨论(0)
  • 2021-01-30 13:43

    In addition to what was already said, I would like to share with you some issues that I had while setting up and the solutions that eventually allowed me to start working with a WSL2/Docker Desktop combo. This is not a complete guide, just another source of troubleshooting!

    My goal was

    1. Start Experimenting with Docker.
    2. Setup my environment so it is as recommended and most comfortable.
    3. Basically to be able to work in a Linux Context while working with Docker Desktop.

    How I went about it

    1. I upgraded my PC from Win 10 Home to Win 10 Pro, to avoid various issues I read that people were having with the Home edition.
    2. I had Docker Toolbox installed and then deleted it as well as the Oracle VM install I had on my PC. I had various small issues, read online that it's best to remove Oracle VM as well.
    3. I installed Docker Desktop.

    Issues and their solutions

      1. A few of the environment variables from the old Docker Tools installation remained. This caused Docker Desktop to misbehave.
      Solution: I deleted all of them. (Any variable name that mentioned Docker)
      2. When trying to connect to Docker on localhost:2375 via Ubuntu WSL2 got the famous "...is docker even running" error. Worth mentioning that on cmd docker was working properly at this stage.
      Solution:
        - Purge a previous installation of Docker I had on my Ubuntu WSL2.
        - Make sure to delete all and any environment variables that mentioned Docker on my ubuntu WSL2.
        - Stop Hyper-v, Rebooted, Started Hyper-V Rebooted on Windows.
        - Install the latest version of Docker via `apt-get`.

    Now running on Ubuntu WSL2 "docker context ls" to check my setup should result in:

    NAME        DESCRIPTION                               DOCKER ENDPOINT               KUBERNETES ENDPOINT   ORCHESTRATOR
    default *   Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                         swarm
    

    Running Docker Info from Ubuntu WSL2:

    Client:
     Context:    default
     Debug Mode: false
     Plugins:
      app: Docker App (Docker Inc., v0.9.1-beta3)
      buildx: Build with BuildKit (Docker Inc., v0.5.0-docker)
      scan: Docker Scan (Docker Inc., v0.5.0)
    
    Server:
     Containers: 3
      Running: 0
      Paused: 0
      Stopped: 3
     Images: 3...
    
    0 讨论(0)
  • 2021-01-30 13:51

    for me this worked for WSL for windows:

    • 1> go to: Turn Windows features on or off
    • 2> deselect "Hyper-V", restart,
    • 3> go to "Turn Windows features on or off" again,
    • 4> select "Hyper-V" again
    • and restart a last time. Afterwards docker was reachable again.

    assuming you have installed docker desktop for windows and Settings->General->Expose daemon on tcp://localhost:2375 without TLS is ticked

    0 讨论(0)
提交回复
热议问题