Microsoft VSCode is a very popular IDE among developers. Docker is another powerful tool to do local devlopment and then push containerized applications to real environments.
It would be very helpful if one can use VSCode installed on local system for development but use docker to run the application. Doing so, we don't need to install any application specific libraries on our local systems.
This approach is very effective and easily configurable for web applications. All one needs to do is to create a Dockerfile, extend the base image, configure required packages and then expose the container port. Local storage is shared with container so that files can be edited directly from your local environment and changes are immediately reflected in the container.
Please refer my article to setup similar environment.
However, how about using docker for some python programs which cannot be exposed on any port and mapped with host system? Let's say I want to run a simple Python program without installing Python on my local system. How can I achieve that? Well, lets dig into that.
First of all launch VSCode and search for Remote Containers extension and install that.
Next, let's create a simple application which requires Python3 to run the programs. We need to create a folder by name ".devcontainer" at the root of the application. Next, create two files in that folder.
devcontainer - Configure settings of the container like user id, path, etc.
Dockerfile - Definition of container where you want to run your programs
Now let's open your application folder and you'll see that VSCode will detect that this project needs to run in a container. Below screenshot explains various steps you may need to go through to run commands in the container from your VSCode terminal.
You can create new python files in VSCode and run in the terminal and the actual executions happens in the container.
You can also view the files in container itself. Following screenshot demonstrates that process.
I will publish some more articles where I explain how to use boto3, pyspark, numpy, etc using this approach.
Hope this article will help someone. Thanks for reading.