Can ddev work with WSL (Windows Subsystem for Linux)? - windows-subsystem-for-linux

As a person working on a Windows machine but enjoying Ubuntu as a working environment I'd like to use ddev in WSL. Is there a way to do that?

2021 Update: DDEV has WSL2 install instructions.
(2018-11-15: Updated for ddev v1.4.0)
It's pretty tweaky, but it can be done. Note that there are no tests or performance results on this, and it's not a supported technique.
Note that WSL actually behaves like linux and uses linux binaries, so you'll use the linux version of ddev.
The biggest problem is that the docker daemon is running under native Windows and WSL has a different filesystem layout, so you have to kind of trick everything on the WSL side to use paths that the Docker daemon will be able to find in native windows.
Start by setting up your WSL/Docker environment as described in this excellent article: https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly#ensure-volume-mounts-work - BUT use DOCKER_HOST=tcp://127.0.0.1:2375 instead of using "localhost" in there.
Install ddev using the Linux instructions.
Make sure all projects are already rm'd with ddev rm -a; projects already running or stopped in native Windows can't be accessed by ddev from WSL-land.
You're probably going to use the web browser on your windows side of the machine, so add the hostname of your project on the Windows side with ddev hostname <yourproject.ddev.local> 127.0.0.1
cd /c/Users//path/to/project (This is a path docker understands.)
ddev start
Visit the project with your browser.
Basically, with this technique you're using paths that the Docker daemon knows how to follow in native windows.
Anyway, it seems to work with a trivial example. Your comments are welcome and we may be able to improve support in the future if people like it.

I have it working (current 1.5.1) inside of WSL. I'm using Docker Toolbox so Docker4Windows may be different.
General setup inside of WSL (I'm using ubuntu)
install docker (apt-get install docker.io)
copy default docker machine certificates to WSL via
cp /mnt/c/Users/[YOUR WINDOWS USER]/.docker/machine/machines/default/*.pem ~/.docker
setup your environment variable inside of WSL (eg. in ~/.bashrc)
export DOCKER_HOST=tcp://192.168.99.100:2376
export DOCKER_TLS_VERIFY=1
export DOCKER_CERT_PATH=~/.docker
The actual values to use can be determined via docker-machine.exe env from the docker toolbox!
At this point you should get a complete output from docker version (don't forget to restart your shell to actually load the modified environment)
Client:
Version: 18.06.1-ce
API version: 1.38
Go version: go1.10.4
Git commit: e68fc7a
Built: Fri Oct 19 19:43:14 2018
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.06.1-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:28:38 2018
OS/Arch: linux/amd64
Experimental: false
Containers can't be started yet as the mount of file systems will fail!
With Docker Toolbox the docker server has the host file system available under /c/. But running from WSL the expected path is /mnt/c/
Generating a symlink is sufficient to make it available docker-machine.exe ssh default 'sudo ln -s /c /mnt/c'
This command has to be rerun after reboot or you have to make the changes permanent via the bootlocal.sh mechanism.
Test your mapping with docker run --rm -i -t -v ${PWD}:/mnt ubuntu bash from WSL.
Install docker-compose, depending on your distribution it is outdated and needs to be replaced with a current version.
Enjoy ddev

Related

File shares in DockerDesktop 20.10.14

I need to configure File share for DockerDesktop installed into my Windows10 machine. With earlier dockerDesktop versions I just added C: into Settings - Resources - File sharing and the changes into any code file below driver C: were immeditely seen in the application running in the corresponding container.
But after update to version 20.10.14
$ docker --version
Docker version 20.10.14, build a224086
such setting is no more available in DockerDesktop. So, how can I set the fileshare now ?
As far as I undestand the mode is wsl 2 backend:
$ wsl.exe -l -v
NAME STATE VERSION
* Ubuntu-18.04 Stopped 1
docker-desktop-data Running 2
docker-desktop Running 2

Is there an way to make WSL2 mount its folders on another drive outside Windows Preview Build 20211?

I've this SSD drive that I bought only for work so I would like WSL2 to write on it. Found this article which I was following thru, to find out wsl --mount is working on Windows Preview Build 20211, not on my build (Win 10 1909 18363.1110).
Is there an way to do this?
Thanks!
Found out later, with a little change of terms on my research, that it could be done as in this tut here: https://www.sitepoint.com/wsl2/
To make it quick for anyone searching around here, you have to export your Linux image, unregister it from wsl and then import it again on the other drive. How it's done:
List your distros
In a Windows Powershell terminal, enter wsl --list. It should return what distros you have installed and if they're running.
Export your distro
In the same Powershell, enter mkdir D:\backup to make a dir for your backup then export it using wsl --export <distro> D:\backup\<distro>.tar. In my case, wsl --export Ubuntu D:\backup\ubuntu.tar.
Unregister the distro
You have to remove it from the C: drive with wsl --unregister Ubuntu and to make sure it worked, after the process is done list all distros again with wsl --list.
Import the distro on another drive
The syntax for this will be wsl --import <distroName> <target\directory> <origin\image>. So if you'd like to make an directory for your WSL in your new drive, just do mkdir D:\wsl or name it anyway you want. I already have a folder for that, so I went with wsl --import Ubuntu D:\wsl-dev D:\backup\ubuntu.tar.
You can verify if it's done by using the very same wsl --list.
And if you want to change your default user from root, follow below steps.
For Ubuntu 18.04, the command to change default user is
ubuntu1804 config --default-user <username>
Took me a while to figure out. Finally found it thanks to this link

Problem while bootstraping ubuntu chef node from chefDK on windows workstation

I'm new to Chef and I have stuck in a problem. I'm using AWS Chef Automate Server and EC2 ubuntu instance as Chef Node. My workstation is local machine where I have installed ChefDK on windows. I have successfully configured the Chef server with ChefDK.
When I bootstrap the node using Knife Bootstrap command, it bootstraps the ubuntu node but shows this error in the end cannot create /etc/chef/trusted_certs/opsworks-cm-ca-2016-root.pem: Directory nonexistent
The command I used here is knife bootstrap myEC2PublicIPHere -N UmaidNode1 -x ubuntu --sudo --run-list "recipe[nginx]" -i .chef/my_key.pem.
After that I added some other cookbooks in the server and run Knife ssh command from my windows workstation to run Chef-client on the node, but this command is not working. I have tried it with different attributes, but always the similar issue FATAL: 1 node found, but does not have the required attribute to establish the connection. Try setting another attribute to open the connection using --attribute.
The command I tried here is knife ssh 'name:*' --attribute myEC2PublicIpHere -x ubuntu -i .chef/my_key.pem 'sudo chef-client'.
Furthur upon running this command knife node show UmaidNode1, it shows the data about node where IP is blank. I don't know why it is not getting this IP here. Showing the output Node Name: UmaidNode1 Environment: _default FQDN: IP: Run List: recipe[nginx], recipe[apache] Roles: Recipes: Platform: Tags:
enter image description here
The issue is finally resolved. I don't know why, but the problem was with the ChefDK version. I was using the latest version 4.8.23. It always creates directory /etcchef but the chef searches for all files in the directory /etc/chef. So it was unable to get the files like client.rb etc.
NOTE: I even make the required /etc/chef directory by myself, but it didn't work.
I installed an older version of ChefDK and now it's working fine.

Using "Remote SSH" in VSCode on a target machine that only allows inbound SSH connections

Is there a way to use the VSCode Remote SSH extension to interact with a remote host that does not allow outbound internet connections?
Is it possible to download the vscode-server files from another system and copy to host?
I read this but I can't connect the server to internet.
When you connect to a host it executes a bash script that wgets or curls a tarball and extracts it in a directory in your home directory. Here's an offline workaround.
Attempt to connect, let it fail
On server, get the commit id
$ ls ~/.vscode-server/bin
553cfb2c2205db5f15f3ee8395bbd5cf066d357d
Download tarball replacing $COMMIT_ID with the the commit number from the previous step
For Stable Version
https://update.code.visualstudio.com/commit:$COMMIT_ID/server-linux-x64/stable
For Insider Version
https://update.code.visualstudio.com/commit:$COMMIT_ID/server-linux-x64/insider
Move tarball to ~/.vscode-server/bin/$COMMIT_ID/vscode-server-linux-x64.tar.gz
Extract tarball in this directory
$ cd ~/.vscode-server/bin/$COMMIT_ID
$ tar -xvzf vscode-server-linux-x64.tar.gz --strip-components 1
Connect again
You'll still need to install any extensions manually. There's a download button next to all the extensions in the marketplace. Once you have the .vsix file you can install them through the GUI with the Install from VSIX option in the extensions manager.
This is kind of a pain and hopefully they improve this process, but if you have a network-based home directory, you only have to do this once.
open vscode -> about
Version: 1.46.1
Commit: cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
Date: 2020-06-17T21:17:14.222Z
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 17.7.0
$COMMIT_ID = cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
A new feature is being added to support offline install
However, you can now solve this issue by a new user setting in the Remote - SSH extension. If you enable the setting remote.SSH.allowLocalServerDownload, the extension will install the VS Code Server on the client first and then copy it over to the server via SCP.
Note: This is currently an experimental feature but will be turned on by default in the next release
https://code.visualstudio.com/blogs/2019/10/03/remote-ssh-tips-and-tricks
A a work around I have done the following:
Desktop ~/.ssh/config
...
Host *
RemoteForward 54321
...
Remote: ~/bin/wget in which ~/bin is added to PATH via .bashrc
#!/bin/bash
export LD_LIBRARY_PATH=$HOME/opt/lib/tsocks/
export TSOCKS_CONF_FILE=$HOME/opt/tsocks/tsocks.conf
$HOME/bin/tsocks /usr/bin/wget $#
Remote: ~/opt/tsocks/tsocks.conf
server = 127.0.0.1
server_port = 54321
server_type = 5
note tsocks binary has been scp-ed to ~/bin/tsocks and ~/opt/tsocks/ has been created with libtsocks.so which is normally stored in /usr/lib64/libtsocks.so
This is a work around that allows me to have wget functionality with out messing with anything outside my profile to get it to work (eg: no root required ... even though I have it).
Current Version of VS Code: 1.48.2
I just kill the wget process on the server end, and let the client download the archive and transfer it to the server end. That's quite easy as below.
make sure that you set in settings.json
"remote.SSH.allowLocalServerDownload": true,
execute the shell scrpits below.
# to find the <pid>
ps aux | grep wget | grep vscode-server
# kill the process
kill -9 <pid>
# then wait for the client downloading and transferring
# optional: If you want to know the progress, just
cd ~/.vscode-server/bin/<commit-id>/
watch -n 1 -d ls -rthl

libvirt and VirtualBox / Getting Started

I'm trying to get started on libvirt with VirtualBox as a virtualization solution. I installed everything and VirtualBox itself is running when using their VBoxHeadless command.
However, libvirt fails to connect to VirtualBox:
# virsh -c vbox:///session
libvir: error : could not connect to vbox:///session
error: failed to connect to the hypervisor
I could not find any hints in the libvirt documentation that point to whether I have to make any domain specific configuration before using virsh.
Does anyone have a hint? Or even better, maybe a tutorial that works through the way of using libvirt, virsh or it's APIs (my later goal) from the ground up.
If you are doing this on Ubuntu, then the problem is their libvirt package is built without VirtualBox support.
You can rebuild the package with support very easily. Something like:
apt-get source -d libvirt
sudo apt-get build-dep libvirt
dpkg-source -x libvirt*dsc
Go into the libvirt directory and edit debian/rules so that instead of --without-vbox it says --with-vbox. You can add an entry to the top of debian/changelog so the package is compiled as a different version (e.g., append ~local1 to the version).
dpkg-buildpackage -us -uc -b -rfakeroot
You'll get new .debs built in the directory above. Use dpkg -i to install the relevant ones (libvirt0, libvirt0-bin, and whatever else you want).
Double-check whether or not you have write access to /var/run/libvirt/libvirt-sock.
The socket file should have permissions similar to:
$ sudo ls -la /var/run/libvirt/libvirt-sock
srwxrwx--- 1 root libvirtd 0 2010-08-24 14:54 /var/run/libvirt/libvirt-sock
I think it could be helpful also to increase the libvirt logging capabilities by running this in your shell:
export LIBVIRT_DEBUG=1
There is Ubuntu PPA for libvirt with VirtualBox support: https://launchpad.net/~cxl/+archive/ubuntu/libvirt