Code Monkey home page Code Monkey logo

python-server-dev-container's Introduction

Containerized Development Environment

This Python development environment is containerized & configured to run in VS Code. Once set up, the extensions and environment dependencies are stored as configuration files within the repository, making sharing and building atop simple and straightforward.

Setup Instructions

  1. Install Docker
  2. Install Remote Development VS Code extension
  3. in Command Pallet (โŒ˜ + โ‡ง + P) type/select "Reopen in container"
  4. Run & Develop with the VS Code Debugger, launch script included!
  5. Develop something!

Tour

This environment is meant as a blueprint; as such I'll detail below the important pieces of the setup.

requirements.txt

Similar to a package.json, this file describes the environment dependencies the repository depends on. There are several python utilities that use this format: pip is the package manager that ships with python, conda and venv both generate virtualized environments using requirements.txt as an input. The pip way of generating this file is pip freeze > requirements.txt while using this file with pip is achieved via pip install -r requirements.txt.

Details

  • <package_name>==<version_number> -- Simple file format: 1 package per line, as described

Links

Dockerfile

Describes the "image" that will be generated to run the application with all the requirements.

Details

  • FROM python:3.12-slim-bookworm -- start with a slim linux distribution (all containers are linux internally) w/ python 3.12 pre-installed. Docker Hub lists available images: python official
  • WORKDIR /usr/src/app -- set's the default director for subsequent commands
  • COPY ./requirements.txt /usr/src/app/ -- copies files from the host machine (local) into the docker container
  • RUN ["pip", "install", "-r", "requirements.txt"] -- Run will run the arguments on the internal command line: this installs all files listed in requiremnts.txt
  • CMD ["flask", "--app", "src/hello.py", "--debug", "run"] -- CMD is like run, but is expected to be the main command for the container. Once the "image" is "built" this will be what is run inside the container when you call docker run <my-container>

Links

devcontainer.json

This file contains the configuration for the portable Dockerized development environment. Importantly, it does not execute the CMD in the Dockerfile above

Details

  • build.dockerfile -- Docker configuration file to build the development environment: relative from variable "${localWorkspaceFolder}/Dockerfile.develop"
  • build.context -- Folder the Docker configuration file should treat as its context: variable ${localWorkspaceFolder}
  • workspaceFolder -- the folder within the docker computer to be used when logging in: "/usr/src/app",
  • workspaceMount -- mount the source directory into the container such that editing within the container updates the same host file, think of them as shared: "type=bind,source=${localWorkspaceFolder},target=/usr/src/app",
    • type=bind -- either bind or volume, but bind is preferable here because we may edit the same files outside of the container.
    • source=${localWorkspaceFolder} -- the source folder to mount into
    • target=/usr/src/app --
  • customizations.vscode.extensions -- VS Code extensions to be installed as the development environment is built:

Links

.vscode/settings.json

This file configures VS Code for the workspace. The settings in this file would overwrite the global settings you may already have configured. Within the container environment many of your local configurations for VS Code will be lost, so a portable and embedded version is ideal in this context.

Details

  • [python] -- applies the contained settings only to python language files.
  • [python].editor.defaultFormatter -- There likely won't be a formatter installed inside the container so we must install it (in devcontainer.json) and then set it as the default formatter. : "ms-python.autopep8"

python-server-dev-container's People

Contributors

walston avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.