Skip to content

awpala/python-devcontainer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Python Development Environment Dev Container

This repo contains a devcontainer-based development environment for Python via VS Code and Docker.

Prerequisites/Dependencies

Install the following on your system before proceeding:

Important

If either VS Code and/or Docker is already present on your system, be sure to update either/both to the most recent version before proceeding. Otherwise, if installing from scratch/initially, on successful installation, it is advisable to reboot your system before proceeding. Default options are recommended for installations (in particular, use WSL rather than Hyper-V for Docker Desktop installation on Windows; this should be the default setting in the installer already).

Launching the Development Environment

First, locate an intended working directory on your system, and clone this repository into it, i.e.,:

git clone https://github.com/awpala/python-devcontainer.git

Note

Alternatively, you can download the source files from GitHub via green <> Code button followed by Download ZIP and then extract the contents into this local host system directory instead.

Next, open this repo as a VS Code project, which should appear as follows:

VS Code should automatically detect the subfolder .devcontainer in the opened project and consequently generate a modal in the bottom-right corner. Click Reopen in Container to create the devcontainer.

Note

If the modal disappears, you can accomplish the equivalent via Ctrl Shift P (or equivalently Cmd Shift P on macOS) to open the Command Palette, followed by search of Dev Containers: Reopen in Container (select this option accordingly).

VS Code will reopen in the devcontainer and commence installation of dependencies (this may take a few minutes on initial launch). On successful launch, it will appear as follows:

Note the container connection status in the bottom-left corner (annotated in the figure above). Furthermore, you can press Enter to clear the setup terminal, as annotated in the figure above.

At this point, the development environment is ready. The default conda user profile dev is loaded in the VS Code terminal, and relevant Python VS Code extensions are also loaded in the devcontainer (e.g., syntax highlighting on creation of a new .py source file). Additionally, note that file changes are propagated in realtime between the devcontainer and the host system (at the original location where the devcontainer was created, i.e., <host-path>/python-devcontainer).

Running Jupyter Notebook

To run the Jupyter Notebook application in the browser, simply open a new terminal (which should have conda enviroment dev preset on launch) and run the command as follows:

jn

(corresponding screenshots)

The default browser will automatically open with the Jupyter Notebook app running on port 8888 (forwarded from the devcontainer to the host system). To proceed, copy the token from the running terminal as follows (alternatively, click on the link having general form http://127.0.0.1:8888/tree?token=<TOKEN> in the terminal to relaunch in the browser with the token comprised of alphanumeric value <TOKEN>):

The top-level directory / in Jupyter Notebook corresponds to the top-level directory in the VS Code devcontainer (i.e., filesystem location /home/dev-files); furthermore, these file changes are propagated in real time to the host system as well, as described previously.

Relaunching the Devcontainer

The devcontainer will run indefinitely, provided that the Docker Engine is running (i.e., via running Docker Desktop app) and that the container is not destroyed.

If VS Code has been closed, the running devcontainer can be relaunched via the Remote Explorer as follows:

Changing Default Profile

The current default profile defines conda env dev having Python v. 3.12. To adjust these settings, simply make corresponding changes to file .devcontainer/Dockerfile (see ARGs entries near the top/start of the file). Furthermore, see third-party dependencies specified in .devcontainer/requirements.txt for corresponding definition of cond env dev (i.e., for consequent modification, if so desired).

Additional References

VS Code

Docker

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published