How I develop in the Ubuntu terminal for Windows 10

This post serves as personal persisted notes about the continuous small tweaks I make to develop efficiently in the Ubuntu terminal on Windows.

So let’s get started!

Let’s see, I installed Ubuntu from the Windows Store. Then I had some problems with the Linux subsystem not being enabled, so I went to the Google mobile and found this link Install the Windows Subsystem for Linux. Then I was done!

gcloud: command not found

Well sh…. I didn’t have any tools, I could of course just sudo apt-get everything -y because I can clearly just flush the Ubuntu installation… but what if I wanted to keep my Ubuntu clean as well?

Enter one of my biggest idols, Jessie Frazelle. “The worst thing you could do to me is install something directly on my host”, hangs vividly in my mind as a variation of something she said at a talk at DockerCon, some years ago.

Containerize everything!

Gul’dan: “You will all keep your hosts clean!”
Grom Hellscream: “.. and what Gul’dan, must we containerize in return?”

Okay, maybe I remember it a little differently, get carried away with the clip below:


These days every honest piece of software has a companion container-image, that you can just run out of the box and everything will work! enough with the </sarcasm> it transfers badly in writing.

First things first anyways, I now had to get Docker working in the Ubuntu terminal; luckily someone’d already prepared everything.

I had a problem with folder-mounting though, so on to the Google-mobile!

“Building” my tools

Then I had to tweak some tooling, to quite get where I wanted to be, like the one below

gcloud sdk

Or aliases, e.g. for working with NodeJS,

npm

$ alias npm='docker run --rm -it --network host \ 
  -v "$PWD":/node \
  node:10.1.0-alpine \ 
  npm --prefix /node'

$ npm install
$ npm run <script>

node

$ function node() {
    docker run --rm -it --network host \
    -v "$PWD":/node \
    node:10.1.0-alpine \
    sh -c "cd /node && node $@";
}

$ node index.js

Resources

~/.bash_profile

export DOCKER_HOST=localhost:2375

# NodeJS development
# npm
## run node-alpine image,
## mount current folder into /node
## run npm with the /node folder
alias npm='docker run --rm -it --network host \
    -v "$PWD":/node \
    node:10.1.0-alpine \
    npm --prefix /node'

# node
## run node-alpine image,
## mount current folder into /node
## cd into /node folder
## pass arguments to node
function node() {
    docker run --rm -it --network host \
    -v "$PWD":/node \
    node:10.1.0-alpine \
    sh -c "cd /node && node $@";
}

Make the whole thing a little nicer

Anyone: I don’t think..
Me: nice is subjective!

But why?

I always add this. Historically I’ve always liked to “keep my host clean”. I studied Computer Science with 3-month courses and had to install all kinds of random tools we’d use a couple of times, and every summer holiday would just include a mandatory format. After learning about VM’s I started using those to isolate the clutter, and now I’m trying this.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.