Angular app Docker Container for development with Visual Studio Code

Manisankar R
4 min readDec 4, 2022

--

when people talk about docker, mostly they talk about deployment. Just create a docker image and push it to Azure/Aws and deploy it. Now we are not going to see about deployment.

Then ???

We are going to see how we can use docker for the development environment with visual studio code.

How should we use docker for development?

No need to worry about local setup. just pull the code and start the docker container.

what is the local setup here?

If you are going to use the angular app and required local setup, need to install the following things in your local system

Node Js — expected version

Angular CLI — expected version.

install required visual studio code extensions for formating

Instead of installing all the required, will create a docker container one time and use it for local setup. Do you believe it? we will see how to do it.

Pull your angular app from GitHub. My example app will add at the end of this blog. this is my example app opened in visual studio.

Install the Visual Studio Code — Dev Containers extension

Press F1 to open the Command Palette.

Type add dev container and select Dev Containers: Add Development Container Configuration Files.

Add Dev Container

Select Node.js & Typescript

Node.js & Typescript

Select the version of the node, in my case I selected 16,

Node version

Select angular CLI and click ok.

Angular cli

Now, it created .devcontainer/devcontainer.json in the root folder

devcontainer.json

add “postCreateCommand”: “npm install”

After the docker image is created, it will do an npm install inside the docker image and inside the app.

Then add configuration for vscode, like extensions. How to add an extension,

now I want to add an Angular Language Service extension. then search extension in visual studio, then click marketplace, it will take you marketplace of visual studio code. Search Unique Identifier, then you get the id of the extension, then add extensions, in the extension block.

The visual studio marketplace
"customizations": { "vscode": { "settings": {}, "extensions": [ "Angular.ng-template"] }}
vs extension code

Now, When you make changes in a file, it should detect changes and reflect them in your browser. then you have to update ng serve command

“start”: “ng serve --poll 2000”

poll param to help detect changes in the docker container environment.

one-time setup is done.

If a new developer comes to your team, don’t ask him to do the local setup. ask him to follow the below steps.

Open Container and start working on Project

Take the latest changes from git

and install Docker locally. open it

in visual studio code, Press F1 and select Dev Containers: Reopen in Container

Loading screen of dev container

starting Dev container
Docker Container

If you notice the right corner, it mentioned Dev container: Node.js & Typescript. If you open a terminal, the location of the terminal is node ➜ /workspaces/docker-container-for-development-example.

I don’t have node.js locally. In the docker dev environment, it shows the node version.

node version in docker.

Then Do npm run start

npm run start

so it shows that output here.

the app is running in the docker container.

Once you completed the work,

press F1 in the visual studio code, select Dev Containers: Reopen Folder Locally

Dev Containers: Reopen Folder Locally

repo will open locally. then you can push your changes to the repo.

When you are working on multiple projects, you don’t worry about the environment. you can keep installing docker and dev container extensions in visual studio code, switch projects then work on the project.

Don’t worry about the environment setup. Think about logic coding.

Example added here

Happy Coding!!!

--

--

Manisankar R
Manisankar R

Written by Manisankar R

Passionate about web/mobile development | Badminton lover | Believe in process | Always look for logic | Information geek

No responses yet