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
Related
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
Exactly the same problem as Ubuntu WSL with docker could not be found
$ docker
The command 'docker' could not be found in this WSL 1 distro.
We recommend to convert this distro to WSL 2 and activate
the WSL integration in Docker Desktop settings.
See https://docs.docker.com/docker-for-windows/wsl/ for details.
But my requirement is different -- I want to
stick with WSL1 (for reasons beyond this topic)
and use Docker for Windows as-is
I.e., I have WSL1 and Docker for Windows installed parallel to each other. This is my current info:
C:> ver
Microsoft Windows [Version 10.0.18363.1379]
C:> wsl -l -v
NAME STATE VERSION
* Debian Running 1
I don't see integration in "Resources -> WSL Integration", and I don't have WSL2 backend enabled in Docker Desktop settings.
Just that I'm getting the above problem -- my docker works anywhere, in CMD, Powershell, git-bash, etc, just not in my WSL.
All solutions that I found are to install Docker for Windows within WSL1 or WSL2, but I want to keep everything as is -- WSL and Docker for Windows installed parallel to each other.
Any solution for that?
The command 'docker' could not be found in this WSL 1 distro.
We recommend to convert this distro to WSL 2 and activate
the WSL integration in Docker Desktop settings.
This means in WSL2, it has a real linux kernel which is required to install docker daemon, then in docker-desktop you could have chance to set docker daemon in WSL2. Otherwise, the docker daemon is running in Hyper-V machine. But, if you stick in WSL1, no chance to run docker-daemon in WSL, so the only option is running docker daemon in Hyper-V machine.
Although above is the fact, still we have chance to let you operate docker ps, docker pull etc. in WSL1 bash just like you operate through CMD, Powershell, git-bash, that is allow Docker to accept requests from remote hosts.
For your case, the steps maybe next:
1. Expose docker daemon in docker desktop settings as next, then click Apply & Restart:
2. Install standalone docker client in WSL1:
$ wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.5.tgz
$ tar zxvf docker-20.10.5.tgz
$ cd docker
3. Set default docker daemon:
$ export DOCKER_HOST=tcp://localhost:2375
4. Verify docker client command:
$ ./docker info
Just FTA, this is the quick hacky workaround that I found, while trying to solve it myself
Change the C:\Program Files\Docker\Docker\resources\bin\docker file to
#!/usr/bin/env sh
#
# Copyright (c) Docker Inc.
binary=$(basename "$0")
"$binary.exe" "$#"
Then docker can work anywhere now, in CMD, Powershell, git-bash, and as well as WSL1.
Note that this hacky workaround is specially for the situation described in OP, might not work for anything else.
I ran the same issue with Ubuntu 20 Distro when trying to use Docker. Below are steps i followed to resole it:
1- I went to microsoft Store and downloaded a recent distro version of the distro, that was Ubuntu 22.04
2- On powershell as admin, i ran the command wsl -l -v to make sure i have the new version
PS C:\WINDOWS\system32> wsl -l -v
NAME STATE VERSION
* Ubuntu Stopped 1
Ubuntu-22.04 Stopped 2
docker-desktop-data Stopped 2
docker-desktop Stopped 2
3- i ran the command: wsl --set-default Ubuntu-22.04 to use wsl 2
I wan now able to use Docker on WSL 2
I have Docker Desktop running with WSL 2 backend. I also have Ubuntu 20.04 installed as my default WSL2 Linux distro.
The problem I am facing is that if I launch C:\Windows\System32\wsl.exe when Docker is running then the shell is initialized with a very long directory path:
/mnt/wsl/docker-desktop-bind-mounts/Ubuntu-20.04/8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1/mnt/c/Windows/System32
However, if I shutdown docker and start a WSL shell again, then it starts at the expected path: /mnt/c/Windows/System32
I can cd into /mnt/c myself but it is annoying that it doesn't start on the right path.
I also tried running wsl -d "Ubuntu-20.04 to no avail.
It seems that my C volume is mounted on both /mnt/c and the long ugly path above.
Has anyone experienced and resolved this issue?
Docker Version: 2.3.0.3 (45519)
It seems to work okay if I start Docker desktop first and then WSL.
I had the same issue and this is what fixed it:
Let's name the folder that mounts with a long name - FL
Delete all the containters in Docker, that are linked to FL
Restart Docker
Inside FL run docker-compose BUT not inside WSL, but on Windows terminal.
Now when you mount FL into WSL by running command like "C:\Windows\System32\wsl.exe -d Ubuntu" - it mounts with a short name.
In summary: the problem for me was an accidental recreating of Docker containers inside my project's folder being in WSL terminal.
I've solved this issue by disabling WSL integration option in Docker settings in Windows at Settings > Resources > WSL Integration
Im trying to use the docker client from inside WSL, connecting to the docker engine on Windows. Ive exposed the docker engine on Windows on port 2375, and after setting the DOCKER_HOST environment variable in WSL, I can verify this works by running docker ps.
The problem comes when i attempt to mount directories into docker containers from WSL. For example:
I create a directory and file inside my home folder on WSL (mkdir ~/dockertest && touch ~/dockertest/example.txt)
ls ~/dockertest shows my file has been created
I now start a docker container, mounting my docker test folder (docker run -it --rm -v ~/dockertest:/data alpine ls /data)
I would expect to see 'example.txt' in the docker container, but this does not seem to be happening.
Any ideas what I might be missing?
There are great instructions for Docker setup in WSL at https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly#ensure-volume-mounts-work - solved most of my problems. The biggest trick for me was with bind-mounted directories; you have to use a path in WSL that the Docker daemon will be able to translate, for example /c/Users/rfay/myproject.
I don't think you need to change the mound point as the link suggests. Rather if you use pwd and sed in combination you should get the effect you need.
docker run -it -v $(pwd | sed 's/^\/mnt//'):/var/folder -w "/var/folder" alpine
pwd returns the working folder in the format '/mnt/c/code/folder'. Pipe this to sed and replace '/mnt' with empty string will leave you with a path such as '/c/code/folder' which is correct for docker for windows.
Anyone stumbling here over this issue follow this: Docker Desktop WSL2 Backend and make sure you are running the version 2 of the WSL in PowerShell:
> wsl -l -v
NAME STATE VERSION
* docker-desktop Running 2
Ubuntu Running 2
docker-desktop-data Running 2
If your Ubuntu VERSION doesn't say 2, you need to update it according to the guide above.
After that, you will be able to mount your Linux directory to the Docker Container directly like:
docker run -v ~/my-project:/sources <my-image>
Specific to WSL 1
Ran into the same issue. One thing to remember is that docker run command does not execute a container then and there on a command shell. It sends the run arguments to a docker daemon that does not interpret WSL path correctly. Hence, you need to pass Windows formatted path in quotes and with back slashes escaped
Your Windows path is
\\wsl$\Ubuntu\home\username\dockertest
Docker command after escaping will probably be like
docker run -it --rm -v "\\\\wsl\$\\Ubuntu\\home\\username\\dockertest":/data alpine ls /data
try
docker -v /:{path} exe
Hope to help you.
How can I share a folder between my Windows files and a docker container, by mounting a volume with simple --volume command using Docker Toolbox on?
I'm using "Docker Quickstart Terminal" and when I try this:
winpty docker run -it --rm --volume /C/Users/myuser:/myuser ubuntu
I have this error:
Invalid value "C:\\Users\\myuser\\:\\myuser" for flag --volume: bad mount mode specified : \myuser
See 'docker run --help'.
Following this, I also tried
winpty docker run -it --rm --volume "//C/Users/myuser:/myuser" ubuntu
and got
Invalid value "\\\\C:\\Users\\myuser\\:\\myuser" for flag --volume: \myuser is not an absolute path
See 'docker run --help'.
This is an improvement of the selected answer because that answer is limited to c:\Users folder. If you want to create a volume using a directory outside of c:\Users this is an extension.
In windows 7, I used docker toolbox. It used Virtual Box.
Open virtual box
Select the machine (in my case default).
Right clicked and select settings option
Go to Shared Folders
Include a new machine folder.
For example, in my case I have included:
**Name**: c:\dev
**Path**: c/dev
Click and close
Open "Docker Quickstart Terminal" and restart the docker machine.
Use this command:
$ docker-machine restart
To verify that it worked, following these steps:
SSH to the docker machine.
Using this command:
$ docker-machine ssh
Go to the folder that you have shared/mounted.
In my case, I use this command
$ cd /c/dev
Check the user owner of the folder. You could use "ls -all" and verify that the owner will be "docker"
You will see something like this:
docker#default:/c/dev$ ls -all
total 92
drwxrwxrwx 1 docker staff 4096 Feb 23 14:16 ./
drwxr-xr-x 4 root root 80 Feb 24 09:01 ../
drwxrwxrwx 1 docker staff 4096 Jan 16 09:28 my_folder/
In that case, you will be able to create a volume for that folder.
You can use these commands:
docker create -v /c/dev/:/app/dev --name dev image
docker run -d -it --volumes-from dev image
or
docker run -d -it -v /c/dev/:/app/dev image
Both commands work for me. I hope this will be useful.
This is actually an issue of the project and there are 2 working workarounds:
Creating a data volume:
docker create -v //c/Users/myuser:/myuser --name data hello-world
winpty docker run -it --rm --volumes-from data ubuntu
SSHing directly in the docker host:
docker-machine ssh default
And from there doing a classic:
docker run -it --rm --volume /c/Users/myuser:/myuser ubuntu
If you are looking for the solution that will resolve all the Windows issues and make it work on the Windows OS in the same way as on Linux, then see below. I tested this and it works in all cases. I’m showing also how I get it (the steps and thinking process). I've also wrote an article about using Docker and dealing with with docker issues here.
Solution 1: Use VirtualBox (if you think it's not good idea see Solution 2 below)
Open VirtualBox (you have it already installed along with the docker tools)
Create virtual machine
(This is optional, you can skip it and forward ports from the VM) Create second ethernet card - bridged, this way it will receive IP address from your network (it will have IP like docker machine)
Install Ubuntu LTS which is older than 1 year
Install docker
Add shared directories to the virtual machine and automount your project directories (this way you have access to the project directory from Ubuntu) but still can work in Windows
Done
Bonus:
Everything is working the same way as on Linux
Pause/Unpause the dockerized environment whenever you want
Solution 2: Use VirtualBox (this is very similar to the solution 1 but it shows also the thinking process, which might be usefull when solving similar issues)
Read that somebody move the folders to /C/Users/Public and that works https://forums.docker.com/t/sharing-a-volume-on-windows-with-docker-toolbox/4953/2
Try it, realize that it doesn’t have much sense in your case.
Read entire page here https://github.com/docker/toolbox/issues/607 and try all solutions listed on page
Find this page (the one you are reading now) and try all the solutions from other comments
Find somewhere information that setting COMPOSE_CONVERT_WINDOWS_PATHS=1 environment variable might solve the issue.
Stop looking for the solution for few months
Go back and check the same links again
Cry deeply
Feel the enlightenment moment
Open VirtualBox (you have it already installed along with the docker tools)
Create virtual machine with second ethernet card - bridged, this way it will receive IP address from your network (it will have IP like docker machine)
Install Ubuntu LTS which is very recent (not older than few months)
Notice that the automounting is not really working and the integration is broken (like clipboard sharing etc.)
Delete virtual machine
Go out and have a drink
Rent expensive car and go with high speed on highway
Destroy the car and die
Respawn in front of your PC
Install Ubuntu LTS which is older than 1 year
Try to run docker
Notice it’s not installed
Install docker by apt-get install docker
Install suggested docker.io
Try to run docker-compose
Notice it’s not installed
apt get install docker-compose
Try to run your project with docker-compose
Notice that it’s old version
Check your power level (it should be over 9000)
Search how to install latest version of docker and find the official guide https://docs.docker.com/install/linux/docker-ce/ubuntu/
Uninstall the current docker-compose and docker.io
Install docker using the official guide https://docs.docker.com/install/linux/docker-ce/ubuntu/
Add shared directories to the virtual machine and automount your project directories (this way you have access to the project directory from Ubuntu, so you can run any docker command)
Done
As of August 2016 Docker for windows now uses hyper-v directly instead of virtualbox, so I think it is a little different. First share the drive in settings then use the C: drive letter format, but use forward slashes. For instance I created an H:\t\REDIS directory and was able to see it mounted on /data in the container with this command:
docker run -it --rm -v h:/t/REDIS:/data redis sh
The same format, using drive letter and a colon then forward slashes for the path separator worked both from windows command prompt and from git bash.
I found this question googling to find an answer, but I couldn't find anything that worked. Things would seem to work with no errors being thrown, but I just couldn't see the data on the host (or vice-versa). Finally I checked out the settings closely and tried the format they show:
So first, you have to share the whole drive to the docker vm in settings here, I think that gives the 'docker-machine' vm running in hyper-v access to that drive. Then you have to use the format shown there, which seems to only exist in this one image and in no documentation or questions I could find on the web:
docker run --rm -v c:/Users:/data alpine ls /data
Simply using double leading slashes worked for me on Windows 7:
docker run --rm -v //c/Users:/data alpine ls /data/
Taken from here: https://github.com/moby/moby/issues/12590
Try this:
Open Docker Quickstart Terminal. If it is already open, run $ cd ~ to make sure you are in Windows user directory.
$ docker run -it -v /$(pwd)/ubuntu:/windows ubuntu
It will work if the error is due to typo. You will get an empty folder named ubuntu in your user directory. You will see this folder with the name windows in your ubuntu container.
For those using Virtual Box who prefer command-line approach
1) Make sure the docker-machine is not running
Docker Quickstart Terminal:
docker-machine stop
2) Create the sharing Windows <-> docker-machine
Windows command prompt:
(Modify following to fit your scenario. I feed my Apache httpd container from directory synced via Dropbox.)
set VBOX=D:\Program Files\Oracle\VirtualBox\VBoxManage.exe
set VM_NAME=default
set NAME=c/htdocs
set HOSTPATH=%DROPBOX%\htdocs
"%VBOX%" sharedfolder add "%VM_NAME%" --name "%NAME%" --hostpath "%HOSTPATH%" --automount
3) Start the docker-machine and mount the volume in a new container
Docker Quickstart Terminal:
(Again, I am starting an Apache httpd container, hence that port exposing.)
docker-machine start
docker run -d --name my-apache-container-0 -p 80:80 -v /c/htdocs:/usr/local/apache2/htdocs my-apache-image:1.0
share folders virtualBox toolbox and windows 7 and nodejs image container
using...
Docker Quickstart Terminal [QST]
Windows Explorer [WE]
lets start...
[QST] open Docker Quickstart Terminal
[QST] stop virtual-machine
$ docker-machine stop
[WE] open a windows explorer
[WE] go to the virtualBox installation dir
[WE] open a cmd and execute...
C:\Program Files\Oracle\VirtualBox>VBoxManage sharedfolder add "default" --name
"/d/SVN_FOLDERS/X2R2_WP6/nodejs" --hostpath "\?\d:\SVN_FOLDERS\X2R2_WP6\nodejs" --automount
check in the oracle virtual machine, that the new shared folder has appeared
[QST] start virtual-machine
$ docker-machine start
[QST] run container nodejs
docker stop nodejs
docker rm nodejs
docker run -d -it --rm --name nodejs -v /d/SVN_FOLDERS/X2R2_WP6/nodejs:/usr/src/app -w /usr/src/app node2
[QST] open bash to the container
docker exec -i -t nodejs /bin/bash
[QST] execute dir and you will see the shared files
I solved it!
Add a volume:
docker run -d -v my-named-volume:C:\MyNamedVolume testimage:latest
Mount a host directory:
docker run -d -v C:\Temp\123:C:\My\Shared\Dir testimage:latest