I am new to docker.
I installed wsland running wsl2 (with Ubuntu) in windows 11 and Docker Desktop to play with docker.
I am curious if there is any difference to run docker command such as docker build between in cmd or in wsl mode?
wsl mode means: I enter wsl before running anything in the cmd.
Hope my question is clear.
If you've installed native Docker packages inside Ubuntu (e.g. with apt) then Docker is unavailable in the Windows host so you can't even run commands from there.
If you've installed Docker Desktop on Windows (the recommended setup) then you're effectively getting integration between both OSes so it doesn't really matter which environment you use. In fact the Linux binaries are wrappers provided by the bundle:
$ ls -al $(which docker)
lrwxrwxrwx 1 root root 48 Aug 23 10:40 /usr/bin/docker -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker
Here is my setup:
Windows 10 PRO - build 19041.153 - insider program - slow ring
Ubuntu 18.04LTS subsystem in WSL2 mode
Docker for desktop 2.2.0.4 - enabled WSL2 integration with my Ubuntu subsystem
I am currently forced to use Windows for development, so I became a
Microsoft insider member and installed ubuntu with WSL2 mode. Docker desktop supports integration for WSL2, so I tried it...
For a week it worked flawlessly. Today after a PC restart, I can't get docker running again. Ubuntu can see the injected binaries from Docker desktop, but it can't connect to windows hosted docker daemon anymore.
When I call in the WSL terminal docker info it returns
$ docker info
Client:
Debug Mode: false
Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info
or with docker-compose up
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.
What I've tried already:
expose daemon without TLS with envs like DOCKER_HOST=localhost:2375, DOCKER_HOST=tcp://localhost:2375, DOCKER_HOST=127.0.0.1:2375, DOCKER_HOST=tcp://127.0.0.1:2375 => same result
uninstall Docker desktop and install previous version
turn off windows firewall
I really, really need this to work. Thanks for any ideas. Weirdest thing is it worked yesterday and I didn't make any changes in system from then...
I know this may be outdated for the present question, but this should save us precious time, especially when Windows 20H1=2004 is going to Production this month (May 2020).
Operating System Version: Windows 10 Education (Same as Enterprise and a superset of Pro).
Version: 2004
Build (Version OS): 19041.264
Others: Windows Feature Experience Pack 120.2202.130.0.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shell: WSL Terminal
First, I have installed WSL v1 previously, then executed the procedure to upgrade to WSLv2, and this error shows up: "ERROR: Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?".
Second, to fix that error, I followed instructions stated here: Link, and it worked.
Third, after some tests I think the missing change in the upgrade, was removing the DOCKER_HOST variable from shell's start script.
SUMMARY: In my case, the procedure for a permanent fix should be the following STEPs:
1. Test if it's your case unsetting DOCKER_HOST variable (See image below).
2. If the error disappears with previous step, then time to fix changes by removing the setting of the DOCKER_HOST variable in the shell's start script (In my case was *$HOME/.bashrc*).
Commented this out:
#export DOCKER_HOST=tcp://localhost:2375
#export DOCKER_BUILDKIT=1
NOTE: Also include DOCKER_BUILDKIT.
3. Close and open the Terminal.
Test in Step 1:
Good luck!!
If it helps anyone else that is having this issue, for me it turned out that my subsystem was suddenly (and "on its own") ticked off in docker's RESOURCES > WSL INTEGRATION settings.
On the Docker Desktop app I had to manually enable my distro integration under
Settings > Resources > WSL Integration
I had installed Docker for Windows, as recommended, to use it with WSL 2 and that does indeed start the docker daemon for you. But I don't need all the fancy features it offers so removed it and was pleased to see about 4GB freed and no extra icon in the system tray.
Now if I need to run docker commands I just begin with:
sudo dockerd &
This way I can have it running on the background on the same shell. Note that in this example I have setup sudo without password. If a password is required, I can do sudo dockerd and open another terminal tab.
Although this works as a quick temporary solution I've seen it cause network issues so I would not recommend it, and prefer using a light VM instead.
I've tried soooo many things, and the stuff that worked for me, and no one ever mentioned to try:
(from Windows Powershell)
wsl --set-default <my-distro>
then and there, I could connect to docker without changing the DOCKER_HOST var.
1.open windows docker desktop --> Setting -->General --> Disable Expose daemon on tcp://localhost:2375 without TLS
2.and then Go to Settings --> Resources --> WSL integration --> uncheck Enable integration with my default WSL distro and turn off integration with distro
3.click apply and restart
4.then go to ubuntu
try docker ps
docker ps
if it does not work, continue to run the following command
unset DOCKER_HOST to disable DOCKER_HOST
Today I just tried it successfully
good luck to you
I have found my issue was due to mis-reading instructions., fixed on my windows version 1909 and WSL 2 with the following commands on CMD:
wsl.exe -l -v
wsl.exe --set-version ${distro-name} ${wsl version}
example:
C:\Users\xxxxx>wsl.exe -l -v
NAME STATE VERSION
* Ubuntu-18.04 Running 1
docker-desktop-data Running 2
docker-desktop Running 2
C:\Users\xxxxx>wsl.exe --set-version Ubuntu-18.04 2
Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
That's it
ISSUE: Cannot connect to the Docker daemon at tcp://127.0.0.1:2375
Powershell
wsl -l -v # ALL DISPLAY "2"
Linux
unset DOCKER_HOST
/etc/init.d/docker restart
Restart Docker
windows docker restart
windows firewall off
Linux docker processes
docker ps
I had the same problem, the solution for me was to set my Ubuntu as the default wsl distribution: wsl --set-default Ubuntu
For whatever it's worth (this is an old thread). Maybe someone else is still desperately trying to solve this puzzle.
I have just stumbled over the solution in my case.
I am running the following
docker desktop version 3.3.3
wsl 2
Fedora 33
Over and over again I ran into this issue "Cannot connect to the Docker daemon at unix:///var/run/docker.sock". Reinstalled, restarted, blablabla.
My ultimate error were access rights on /var/run/docker.sock, and I am running wsl under my personal user
srw-rw---- 1 root docker 0 May 7 10:29 /var/run/docker.sock
So if I run as root (sudo docker info) or I put myself into group "docker" (sudo usermod -aG docker $USER) I'm all well. Please look here https://docs.docker.com/engine/install/linux-postinstall/
There is another very basic catch:
Ensure virtualization is enabled in the BIOS.
Please enable the Virtual Machine Platform Windows feature from the selection of additional Windows Features.
Now my motherboard is being very old, the BIOS does not support
Enabling Virtualization.
Hence no solution will work for me.
WSL Version 1 or 2 will come from Windows Update automatically.
After hours, my docker worked using following method.
Go to docker desktop --> Setting -->General --> Disable Expose daemon on tcp://localhost:2375 without TLS
Go to Settings --> Resources --> WSL integration --> uncheck Enable integration with my default WSL distro and turn off integration with distro
Restart Docker desktop
Now in WSL,
unset DOCKER_HOST
Now try,
docker ps
The accepted answer is mostly correct. However, I wanted to specify that when using WSL2 + Docker Desktop:
You must unset DOCKER_HOST which was previously needed in WSL1
Mine was defined in ~/.bashrc in both Windows and WSL.
Delete in both. Also delete in Windows env variables via Control Panel.
Check with env | grep -i docker to make sure it's gone.
You must also set the correct settings in Docker Desktop
Uncheck Export daemon on tcp://localhost:2375 without TLS
Check Use the WSL2 based engine
Resources -> WSL Integration -> Check Enable integration with my default WSL distro
Now, you can do a simple docker info to check if you're running the same server version in WSL and in Windows (Powershell).
you can consider upgrading your version to 19582.1000 , it's work for me.
See this issue.
I'm going through this tutorial
Dockerizing Flask With Compose and Machine - From Localhost to the Cloud
When trying to create a virtualbox with the command below
docker-machine create -d virtualbox dev;
I have the following error
Error creating machine : Error in driver during machine creation. This computer doesn't have VT-X/AMD enabled. Enabling it in the BIOS is mandatory
(Addendum: I'm running an ubuntu image on a virtual box. The physical host is a windows machine. The VT VT-X/AMD is enabled both , in the bios and in the virtualbox.)
Reading here and there, it seems to be a normal behavior because I'm trying to create a virtualbox within a virtualbox -> Click here for the explanation
What command should I use instead of docker-machine ?
Any insights are more than welcomed ...
Update: I've asked 3 additional questions to #VonC after his initial answer. Please find the questions below , in italic
1) How should I make the virtualbox and the docker config see that new "virtualbox"?
2) Will the ubuntu box, be able to do the docker-compose and build the container on that host?
3) If I'm pulling an image like debian, how can I use it as a machine and build an container on top of it?
If you do not want to change the BIOS settings, please run the below command.
I have the same problem because I have Hyper-V manager installed in my Windows 8 server. To avoid this issue I ran the below with the below option
--virtualbox-no-vtx-check
Example: docker-machine create default --virtualbox-no-vtx-check
I'm in a VM already , running ubuntu. Physical host is a windows machine
Then you don't need docker-machine.
You would create a small Linux image from windows with (again, type in a regular Windows CMD shell)
docker-machine create -d virtualbox dev
But on a full-fledged Ubuntu VM, you just need to install docker and run it directly.
If you need to use docker-machine, just copy (on Windows) v0.6.0-rc1/docker-machine_windows-amd64.exe as docker-machine.exe anywhere you want.
Also: set VBOX_MSI_INSTALL_PATH=C:\Program Files\Oracle\VirtualBox\ (if your VirtualBox is installed there)
You now can use docker-machine -d virtualbox dev.
2) Will the ubuntu box, be able to do the docker-compose and build the container on that host?
Yes, no issue there. The installation is straightforward.
3) If I'm pulling an image like debian, how can I use it as a machine and build an container on top of it?
You simply write a Dockerfile starting with FROM debian:jessie (see an example here), add some commands (RUN, COPY, ...): for instance:
FROM debian:stable
RUN apt-get update && apt-get install -y --force-yes apache2
EXPOSE 80 443
VOLUME ["/var/www", "/var/log/apache2", "/etc/apache2"]
ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
Build it (docker build .)and run it (docker run).
I'm trying to something with Docker.
Steps I'm doing:
- Launch Docker Quickstart Terminal
- run docker run hello-world
Then I get error like:
bash: /c/Program Files/Docker Toolbox/docker: Bad address
I have to say that I was able to run hello-world image, but now I'm not. I don't know what happend.
I don't know if it matters however I had some problems at instalation step.
Since I have git installed in non standard location. However it seems git bash.exe working correctly for Docker.
My environment:
Windows 10
Git 2.5.0 (installed before Docker)
Docker Toolbox 1.9.1a
I have the same issue with bash: /c/Program Files/Docker Toolbox/docker: Bad address
I thought the problems is "bash doesn't support docker.exe".
SO I fix this problem by use powershell ,not the bash.
and if you use powershell maybe face this
An error occurred trying to connect: Get http://localhost:2375/v1.21/containers/json: dial tcp 127.0.0.1:2375: ConnectExenter code here
tcp: No connection could be made because the target machine actively refused it.
You can export variable from bash use export and import to powershell by this below
$env:DOCKER_HOST="tcp://192.168.99.100:2376"
$env:DOCKER_MACHINE_NAME="default"
$env:DOCKER_TLS_VERIFY="1"
$env:DOCKER_TOOLBOX_INSTALL_PATH="C:\\Program Files\\Docker Toolbox"
$env:DOCKER_CERT_PATH="C:\\Users\\kk580\\.docker\\machine\\machines\\default"
that's all
ps:I found this problem fixed by update git from 2.5.0 to 2.6.3.
Not entirely sure what the issue is, report it to the project on github. I find the docker mac and windows tools a bit flakey from time to time as they are still maturing. If you don't mind seeing what's underneath, you can try running docker-machine directly or set up your own host pretty quickly with Vagrant.
Docker Machine
Run a command or bash prompt to see what machines you have.
docker-machine ls
Create a machine if you don't have one listed
docker-machine create -d "virtualbox" default-docker
Then connect to the listed machine (or default-docker)
docker-machine ssh default-docker
Vagrant
If that doesn't work you can always use vagrant to manage VM's
Install VirtualBox (Which you probably have already if you installed the toolbox)
Reinstall Git, make sure you select the option for adding ALL the tools to your system PATH (for vagrant ssh)
Install Vagrant
Run a command or bash prompt
mkdir docker
cd docker
vagrant init debian/jessie64
vagrant up --provider virtualbox
Then to connect to your docker host you can run (from the same docker directory you created above)
vagrant ssh
Now your on the docker host, Install the latest docker the first time
curl https://get.docker.com/ | sudo sh
Docker
Now you have either a vagrant or docker-machine host up, you can docker away after that.
sudo docker run -ti busybox bash
You could also use PuTTY to connect to vagrant machines instead of installing git/ssh and running vagrant ssh. It provides a nicer shell experience but it requires some manual setup of the ssh connections.
I have docker (Docker version 1.3.1, build 4e9bbfa) running on virtual machine.
I have created some containers that has supervisor running to allow sshd and apache running.
Right now in order to do some changed i have to log in to ssh and run sh script, I tried exec command, but it seems not working on that server.
What i did to examine a problem: created file named host.txt in root (/) folder of host (where docker daemon is running) and executed
docker exec {container name} ls /
and it gave me list where host.txt present (Not that I have not mounted / into containers / (i even dont know if its possible))
I made exact same container on exact same docker version and executed same test on my ubuntu 14.04 machine, and it works as expected (no host.txt in list)
Any ideas why this might be happening?
I found what caused the issue
kernel < 3.8 is not supported
https://github.com/docker/docker/issues/8976
So for example on following machine it will not work:
uname -a
Linux VIR005-M033-APP 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux