Running docker on WSL (Windows Subsystem for Linux)

My build toolchain is frequently in there for node based applications, and I was looking for a way to run docker commands from WSL (Windows Subsystem for Linux https://docs.microsoft.com/en-au/windows/wsl/install-win10 ).

Note: The below steps are a quick way to get it working but involves disabling TLS authentication. A more involved way to do this without disabling TLS can be found at https://blogs.technet.microsoft.com/virtualization/2017/12/08/wsl-interoperability-with-docker/

 

This setup puts the docker engine in Windows on top of Hyper-V, but allows you to control it either from Windows, or within WSL by connecting it to the Windows Docker Engine.

  1. Install docker for windows https://docs.docker.com/docker-for-windows/install/
  2. Go into the Docker for Windows settings and expose daemon on localhost
    docker windows settings
  3. Install docker in WSL (it’ll just install the client) https://docs.docker.com/install/linux/docker-ce/ubuntu/
  4. Tell WSL to look for a docker engine on localhost
    TIP: put the export into your ~/.bashrc so you don’t need to run it ever time.
    export DOCKER_HOST=tcp://127.0.0.1:2375

Now you will be able to run standard docker commands run new images, show the running containers, etc. docker linux

 

Advertisements

Resolving IPFS API CORS issues

I keep being hit by this issue when trying to configure my IPFS node to allow programmatic access to the API.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:5001/api/v0/add?stream-channels=true. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

The answer is to configure the API permissions of the IPFS configuration.


ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '[\"*\"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '[\"PUT\", \"GET\", \"POST\"]'

IMPORTANT: After making any configuration changes you need to restart the IPFS daemon in order for the new settings to take effect

I had gone wrong as I had been trying to change the GATEWAY.HTTPHeaders instead of API. I also didn’t realise I needed to restart the daemon.