Docker + VS Code

It was pretty easy to set up a docker workstation that resembles the kind of env I use for node dev. I just needed to make a Dockerfile like this:

FROM ubuntu:latest
# I don't remember why I needed to set up timezone, TBH . I probably just Googled it somewhere after some warning during build.
ENV TZ=America/Winnipeg
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# I've just always used aptitude on Ubuntu. ag is just so much better than grep. etc.
RUN apt update && apt install aptitude sudo git silversearcher-ag vim -y
# This creates a new user for me. I prefer working with my own user instead of root.
RUN useradd -rm -d /home/username -s /bin/bash -g root -G sudo -u 1000 username
RUN echo 'username:password' | chpasswd

Build the image

From there you build the image with docker build -t dannyb/my-dev . inside the dir with the Dockerfile. This takes a few minutes.

Start the instance

Run docker run -d dannyb/my-dev to start the instance. Now it’s ready to be connected to with VS Code.

Connecting with VS Code

For VS Code setup, I followed these instructions. Now I just open up VS code, press ctrl-shift-P and select the Remote-Containers: Attach to Running Container... option. In the box that opens it will have all your running containers listed, along with the image they were created from. Select the one that says dannyb/my-dev and it basically mounts it. Open up the terminal and you’re logged in as root into the docker instance! The first thing I run there is su username to switch to my user, and cd to go to the user’s home dir.

Setting up SSH key to be able to clone repos

You might well know how this is done. I tend to run ssh-keygen, then cat ~/.ssh/id_rsa.pub to copy my pub key. Then you add it to GitHub or Bitbucket or wherever the repo you’re gonna work is.

After this is done, you can clone the repo. Once you’ve cloned the repo, press the “Open Folder” button in the Explorer sidebar of VS Code, and select the cloned repo dir. This actually restarts your terminal session, so just run su username again to switch to your user.

Installing node

I tend to do this with nvm. The installation instructions are pretty short. You can then install whatever version of node you need.

That’s pretty much it

There are any number of other things I end up setting up, specific to my likes and needs of the project.

Advertisement

Published by

Dan Bernardic

A Winnipeg Web programmer. Proud member of the Skip the Dishes team. Experienced with Web technologies, e.g. HTML5, CSS, ( Server-side ) JS, PHP, WordPress, MVC, etc.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s