Azure, Docker, Linux, Technical

Bash on Windows Productivity Talk

The bi-annual Denver Dev Day was last week and I had the opportunity to present a topic titled “Using Bash on Windows to Increase your Productivity” to an awesome room of fellow techies. The idea for the session came from my increasing use of Bash and Linux, specifically Windows Subsystem for Linux (WSL), and I thought this talk might not only help others learn a few new tools or tricks but also help me learn what others are doing. I was right on both accounts! If you were there, thanks for coming and I hope it was worth your time investment. If you weren’t there, the session abstract and slides are below. Although, the majority of the time was in Bash showing different scenarios and trying different things folks threw out at me, which was fun! Here’s a sampling of what I showed:

  • Edit Windows files, with mnt and alias
  • Built in VS Code support
    • Launch project from bash
    • Integrated shell
  • Run any Win exe
    • Echo $PATH to show what was included and my modifications
    • Launching Visual Studio 2017
    • Docker tools
    • K8s / minikube
      • Running minikube start requires window to have administrator rights, so we discussed differences between Windows and Linux users/permissions
  • Run bash from CMD
    • dir | bash “grep Desk“
    • bash -c “ls -lh” | findstr Desk
  • Azure
    • Multi-window/multi-account (I use a separate Linux user for each Azure subscription)
      • Az account show | jq .name
    • Multi-pane with Help
  • Dotfiles (My work-in-progress dotfiles)
    • Github for environment consistency & rebuild
  • Shell in Azure

Session Abstract:

Did you know Windows 10 can run Bash on Linux?? While it may seem weird seeing those words together, that’s no reason to shy away and not consider how this new capability can be leveraged to increase your day to day productivity. Think about all the Linux features, code samples, tutorials and tools that are out in the world. Now think about all the Windows counterparts. Bash on Windows gives us the option to use all of it on a single operating system and I’ll show you how!

This session will show you how to get up and running and then we’ll spend some time looking at specific development scenarios and why you would want to use Bash. If development isn’t your focus, we’ll also look at some DevOps scenarios targeting Azure. Finally, I’ll show you some of my favorite tools, tips and tricks along the way that can help you leave the room with knowledge you can immediately put to good use.

Docker, Linux, Technical

MobyLinuxVM Root Access

I’ve needed/wanted this a couple times so posting here to make it easier to find. When using Docker for Windows in Linux mode, it creates a Linux VM running in Hyper-V which actually hosts the containers you create. If you ever need to access that VM, here’s a method that works (thanks to Docker Saigon):
#get a privileged container with access to Docker daemon
docker run --privileged -it --rm -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker alpine sh

#run a container with full root access to MobyLinuxVM and no seccomp profile (so you can mount stuff)
docker run --net=host --ipc=host --uts=host --pid=host -it --security-opt=seccomp=unconfined --privileged --rm -v /:/host alpine /bin/sh

#switch to host FS
chroot /host

 

Docker, Linux, Technical

Oracle Database on Docker for Windows

Coming out of DockerCon this year one of the announcements I was most excited about was from Oracle with their Docker support. I don’t know why I was excited about it as I haven’t used Oracle for a project in over 12 years, but odd things excite me. Since I have Docker for Windows running on my Windows 10 laptop, I decided I would use that to create an image of Oracle Database 11.2.0.2 Express Edition. I won’t rehash the steps here as the good folks at Oracle have done a decent job of this already, but I will call out a few things I noticed:

  • Don’t un-compress the installation binaries after downloading. Yeah, I know they call that out in the docs, but I missed it initially.
  • Be patient. Or multi-task.
    snip_20170522172249
  • And most importantly, Express expects at least 2048MB swap space. The MobyLinuxVM used by Docker for Windows only has 1024MB. So you will get an error stating:
    ”This system does not meet the minimum requirements for swap space. Based on the amount of physical memory available on the system, Oracle Database 11g Express Edition requires 2048 MB of swap space. This system has 1023 MB of swap space. Configure more swap space on the system and retry the installation. “

So unless someone out there can tell me how to set up a larger swap space in that VM, we are stuck and can’t use Docker for Windows. Dammit. I did tag on to an existing Docker forum post, so we’ll see if that bears any fruit.

In the meantime, I fired up an Ubuntu image in Azure and installed Docker and used that to create the container. I didn’t create it with swap space so I did have to go in and add that (I used this method), but once that was setup the image was created just fine. Previous note applies regarding patience and/or multi-tasking.

snip_20170522173310

Not the smallest of images, but there you have it. Now I can fire up an Express Database running in Docker by running:

docker run –name oracleexpress –shm-size=1g -p 1521:1521 -p 8080:8080 -e ORACLE_PWD=tmppassword oracle/database:11.2.0.2-xe

After about 5 minutes, you’ll have a running container! To test the connection and make sure it was running, I logged in using sqlplus from the container:

docker exec -ti oracleexpress sqlplus system/tmppassword@//localhost:1521/XE

Connection successful, and I was able to query the database!

snip_20170522212954

Here’s the image up on Docker Hub if you just want to pull it and start playing.

Now to figure out that MobyLinuxVM swap space…

P.S. If there was any doubt it would run on Windows 10, here it is running on my Windows machine after pulling the image down from Docker Hub (click the image for full screen):

Linux, Technical

Launch Visual Studio from Bash on Windows

Since I’m starting to use Bash on Windows (WSL) more regularly, I added a quick way to launch Visual Studio 2017.

  1. Edit .bashrc and add the VS path (I’m obviously using Enterprise so your path may be different):  export PATH=$PATH:”/mnt/c/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE”
  2. I chose to add an alias, so I also added this to my .bashrc:  alias vs2017=devenv.exe
  3. Reload your shell:  . /.bashrc

Now I can quickly pop open Visual Studio by using “vs2017”. For example, to open an existing solution I can navigate to the folder containing the .sln and simply type “vs2017 mysolutionfile.sln” at my bash prompt and VS2017 will fire up with that project loaded.

Here’s my .bashrc if you want to see the full file.