Docker on Windows tips & tricks

Just some tips & tricks on Docker on Windows I documented for myself.

Location of Docker daemon logs

The Docker daemon logs can be found in the following location.

C:\ProgramData\Docker

By default C:\ProgramData is hidden in Explorer, you need to make it visible in the options (File -> Change folder and search options, select tab View, select the option ‘Show hidden files, folders and drives’ under ‘Hidden files and folders’).

Change folder and search options

WTF!?! Docker asks for Azure AD credentials when sharing C drive

On my Docker quest I was surprised once again. I wanted to share my drive with my Docker container. I was presented with a login dialog that asked for my Azure AD credentials. Azure AD credentials? Seriously? Do I have Azure AD credentials?

UPDATE 9 November 2018

It turns out you do not have to use an Azure AD account for Shared Drives at all. You can just create a local account (i.e. DockerHost) using the instructions below points 2 to 4 .

The confusing part is that the dialog displayed the username as AzureAD\MyName. This didn’t ring a bell. After fiddling around I figured out that I could use my Office 365 credentials, but the username needed to be changed to my email address in the following format AzureAD\[email protected]. Go figure.

After logging in nothing happened and the share was unchecked again. WTF?!?!

After googling around I found the following post Sharing your C drive with Docker for Windows when using Azure Active Directory by Tom Chantler, which gave me enough information to fix the problem.

I had to make to three changes to the solution he describes in his post:

  1. I do not have Azure AD credentials. So I used my Office 365 credentials, which also uses Azure AD. So instead of the username being AzureAD\MyName, I had to change it to AzureAD\[email protected].
  2. I’m running Windows 10 Professional. It initially would not let me create a local users who’s username was not an email address. In the first dialog I needed to select ‘I don’t have this person’s sign-in information’ and in the next step ‘Add user without Microsoft account’. Then I could create the user with the same username (MyName) without the Azure\ prefix.
  3. Change the account type to Administrator.
  4. Go to the Docker Settings and select Shared Drives and use the local user account created in the previous step to authenticate. It should work now.

 

After that the C drive was shared. Whooha!

Docker: incorrect username or password

I’m reacquainting myself with Docker. My first steps were dodgy. I immediately ran into problems testing if Docker was installed correctly on my Windows 10 machine, when I wanted to execute the hello-world image.

docker run hello-world

Which threw the following error.

Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: unauthorized: incorrect username or password.
See 'docker run --help'.

It turned out the problem was that I was a little to eager when I signed into the Docker Hub in the Docker Settings.

Screenshot

After logging out with the following command it worked.

docker logout

Go figure…

Accessing home folders from Windows Subsystem for Linux in Explorer

Are you running Windows Subsystem for Linux (WSfL)? Ever wondered where the home folders are stored so that you can access them from Explorer? Seek no further for here is the answer.

Every distribution has it’s own location. They can be found under:

%LOCALAPPDATA%\Packages

For Ubuntu 18.04 you can find the home folders in the following location:

%LOCALAPPDATA%\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgc\LocalState\rootfs\home

Enjoy!

Change root password Windows Subsystem for Linux

Today I was setting up Windows Subsystem for Linux and wanted to change to the root user using the command:

su -

I was prompted for the password, but had no idea what it was. So I needed to figure out another way of switching to the root user instead of prefixing every command with sudo. Did I say switch and prefix and sudo? O yes, stupid me.

sudo su

Don’t forget to exit once you are done. And be careful not to wrech havoc while working under the root account. Have fun!

Plugin Manager removed from Notepad++

I needed the compare plugin today. You used to be able to select the Plugin Manager under Plugins -> Plugin Manager. But it was gone 😦 It turns out it has been removed from the standard installation and has to be installed separately. I haven’t been able to find out why. Here quick instructions how to install Plugin Manager.

  • Download the latest version of Plugin Manger from GitHub. Make sure you download the correct version 32 or 64 bit depending on the version of your operating system.
  • Unzip the file.
  • Copy the two directories to the Notepad++ directory. In my case C:\Program Files (x86)\Notepad++.
  • Restart Notepad++.

Plugin Manager is available again under Plugins -> Plugin Manager. Yeah!

Validating a json file from the command line in Linux

Today I needed to validate a json file on one of my servers. It turns out there is a simple nodejs program or actually a linter to do this with.

Just execute the following line and you are in business.

sudo npm install jsonlint -g

This assumes nodejs is already installed. If not, execute the following line.
sudo apt-get install -y nodejs npm

To validate a json file run the following command.

jsonlint -qc settings.analyzer.json

When running the program the first time I ran into the problem that the json file contains comments. Yes, I know this is not in line with the spec, but it is damn handy for understanding the file. So I needed to strip the comments to valiate the file. After googeling around a bit I found an awk command to do just this. Try the following command.

awk '{sub(/\/.*$/,"")}1' settings.analyzer.json > settings.analyzer.json

Now run jsonlint again and it should work.

P.s. I know the title of this post says Linux, but jsonlint will also work under any other system that nodejs runs on.

Hope this saves someone some time.

Using the hosts file on Windows with ports

As you might or might not know I’m running Profit Trailer (PT) on a VPS. To be safe the GUI is not accessible to the outside world, but only through an SSH tunnel. It has been irritating me for a while that the URLs are not readable, e.g. localhost:8081. I wanted readable URLs without ports in them. Today I finally figured out how to do this using a combination of host file and the Windows networking tool netsh.

Continue reading

Surface Pro 4 shutsdown when I click the on/off button

When I pressed the on/off on my Surface Pro 4 running Windows 10 it would shut down! Really irritating.

After searching around for a while I found the setting under System Settings that controls the behavior of the on/off button.

  • Open Control Panel > Power Options > System Settings
  • Change the action when the on/off button is pressed to ‘Sleep’.

That’s it. Another problem solved!

Python and Windows

I’m back… It has been a while since my last post. To busy doing other things and not keeping up with my techie skills. I have decided it is time for some new projects. I have a few ideas lined up. Python, Flask, Angular 2 and Ionic 2 are my tools of choice. So I will be blogging about my adventures the comings weeks, months, …

Okay, this blog is going to be on setting up Python on Windows. Just some quick for myself with notes for later reference.

  • Install Python
  • Set environment variable %PYTHON27%
  • Add the following Python dirctories to path: bin & scripts
  • Setup virtualenv, a tool for creating isolated Python virtual environments, each with their own libraries and site-packages:
    pip install virtualenv
  • Install virtualenvwrapper, provides a set of commands which makes working with virtual environments much more pleasant. It also places all your virtual environments in one place:
    pip install virtualenvwrapper-win
  • Add an environment variable WORKON_HOME to specify the path to store environments. My choice: %PYTHON27%\env.
  • For an  overview of the main commands check the repository on GitHub.
  • In order to keep your environment consistent, it’s a good idea to “freeze” the current state of the environment packages. To do this, run:
    pip freeze > requirements.txt
  • This will create a requirements.txt file, which contains a simple list of all the packages in the current environment, and their respective versions. You can see the list of installed packages without the requirements format using “pip list”. Later it will be easier for a different developer (or you, if you need to re-create the environment) to install the same packages using the same versions:
    pip install -r requirements.txt
  • Install Flask-DebugToolbar an extension that adds a toolbar overlay to Flask applications containing useful information for debugging:
    pip install flask-debugtoolbar
  • Check the Flask-DebugToolbar documentation for more information on the use.
  • Install initpy that helps initialize Python projects. It has support for different types of projects: single file project, Flask, Tornado Web, Falcon and Hosted.
    pip install initpy