26
Create disposable development environment in remote server using Docker
Its easy to create development container using remote containers extension of VS Code, but what if we want to create such disposable development server in remote server using docker? In this article I will show you how to create user in ubuntu container runing on docker, also i will provide steps to connect that disposable container to VS Code.
I assume you already installed Docker and added user into docker group, to create disposable development environment we will use ubuntu:focal image from docker registry.
Run this command to create detached interactive ubuntu server
docker run -dit ubuntu:focal /bin/bash
To create container with bind mount, run this command in any folder
docker run -dit -v $(pwd):/root — name test5 ubuntu:focal /bin/bash
In Docker section of VS Code check where your server and right click it (Incase you don't have docker features in VS Code, Install Docker extension)
Select Attach Visual Studio Code, now VS Code will connect to the docker container running in remote server.
You can use development container as a root user
To create user in container follow below steps:
firstly we have to add sudo package to give admin previleges to the user
apt update
apt install sudo
after that add user in groups to get admin previleges.
adduser tejas sudo
adduser tejas tejas
groups tejas ( to check user’s is groups)
now switch to user from root
su - tejas
to automatically open terminal in user folder
install zsh, oh-my-zsh
change default shell of vscode terminal to zsh
and add these commands in .zshrc config file
su tejas
cd /home/tejas
If you have any questions ask me on twitter: https://twitter.com/tejasc0
26