pydock - Docker-based environment manager for Python

Related tags

Miscellaneous pydock
Overview

pydock - Docker-based environment manager for Python

GitHub GitHub tag (latest SemVer pre-release) GitHub Repo stars GitHub forks GitHub watchers

⚠️ pydock is still in beta mode, and very unstable. It is not recommended for anything serious.

pydock is a poor man's Python environment manager fully based on Docker. You can think of it as a replacement for virtualenv. In reality, pydock is just a very thing wrapper around Docker, so everything you can do with pydock you can also do it yourself just with Docker.

The purpose of pydock is to avoid having to install anything at all in your system, and instead manage everything using Docker. In short, pydock gives you an interface similar to most Python environment managers, but uses Docker under the hood, creating dockerfiles, images, and containers as necessary. This creates a bunch of additional headaches, that's for sure, but it has some nice conveniences.

With pydock you can create "virtual" environments, which are actually Docker images, and manage them similarly as with virtualenv and any other Python environment manager. Every environment you create has associated dockerfile and requirements.txt files which provide a completely platform-independent description of that environment. Thus, if at any point you want to migrate those environments to another computer, you just need to copy these files, and run pydock build there.

Design

pydock's mantra is zero-dependencies and absolute freedom. This means it will never create an environment that requires you to install anything to use, not even pydock (outside of Docker, that is, but everyone is already using Docker, right?) In particular, these are some principles we abide to:

  • Use of open standards for decribing environments: Right now the definition of an environment is just a dockerfile and a requirement.txt. There is not and will never be any pydock-specific file there. This means you completely control what goes into an environment, and will never be locked into using pydock for runing or modifying an environment.

  • Depend only on the standard library: Since pydock is supposed to remove your need to install things in your system's Python, it cannot depend on anything that is not bundled in the standard Python distribution that comes with most operating systems (we're talking real operating systems here 😛 ).

Installation (sort of...)

pydock is a single Python file with no dependencies outside the Python standard library and Docker. So you can just download it, give it execution permisions, and add it to your path.

In Linux one way to do this is with this convenience script:

curl https://raw.githubusercontent.com/apiad/pydock/main/install/linux.sh | sudo bash

If you only want to use pydock inside a specific project, then you can just download the pydock.py file into your codebase and commit it to your repository. Then you can use it locally as (provided you gave it execution permisions):

./pydock.py --local  [args...]

Usage

Run pydock to see all available commands, and run pydock to see a small help for that command.

pydock can run in global or local mode, the difference being where it will store the environments configuration. In global mode, everything will be stored in ~/.pydock, at the /home of the current user. In local mode, everything is stored inside a .pydock folder at the current working directory. The rules to decide whether to run in global or local mode are:

  • If you explicitely type pydock --local it will be local. Likewise, if you explicitely type pydock --global it will be global.
  • If no explicit flag is used, then if there is a .pydock folder already created in the current folder (i.e., you ran pydock --local sometime before), it will default to local mode.
  • Otherwise, it will run in global mode.

We recommend global mode when you're creating an environment for interactive coding, e.g., for notebooks, one-off scripts, etc. They are stored in your home folder and can be accessed from anywhere.

Use local mode when you're creating one or more environments for a specific project. Store them with the project source code and probably even commit them to version control, so that all developers share the same environments.

In any moment, you can type pydock config and it will tell you whether it is running in local or global mode.

Creating an environment

Run pydock [--local/--global] create to create a new environment with a given name and Python version. For example:

pydock create datascience 3.8

This command will do the following:

  • Create a new folder datascience inside .pydock (wherever that folder is depends on the local vs global mode).
  • Create a dockerfile and requirements.txt files inside that folder.
  • Run docker build in that context, effectively creating a new image with your desired Python version.

By default, that image will have a user named like the user who run pydock create (this can be customized via configuration).

Executing a shell in an environment

After creating an environment, if you run docker images you'll see a pydock-:latest image, which corresponds to your environment. You can easily start it with (continuing with the previous example):

pydock shell datascience

This will execute a docker run ... datascience bash command tailored to that environment with some additional tidbits. One is that your current working directory will be mounted inside the newly created container's /home/, which will be the starting working directory. Thus, inside the container, whatever you do will be reflected back in your host filesystem, hopefully with the right permissions.

Managing dependencies in an environment

In any existing environment pydock can help you install new dependencies while keeping updated the Docker image and tracking all packages. For example:

pydock install datascience pandas

This will launch a fresh container in the datascience environment and install pandas. pydock will commit the container and re-tag the new image such that it replaces the existing one for this environment, effectively saving the changes you did to the environment. Additionally, the requirements.txt will be updated with the contents of pip freeze, such that next time you call build you'll have the same environment.

Likewise, you can use pydock update and pydock uninstall to update / uninstall dependencies in an environment, with the same syntax and it will do what you expect.

Rebuilding an environment

At any moment, the pydock- images that correspond to each environment should be up-to-date but, if you manually modify the dockerfile or requirements.txt (which you are absolutely free to do), you can run this command to rebuild and tag the corresponding image.

pydock build <name>

This command is also useful if you want to move environments around. For example, by commiting your local .pydock folder into source control for a given project, other developers can easily run pydock build ... after checkout and the corresponding environment(s) will be created.

If you run build manually, pydock will not delete the old image for that container, which will appear labelled . Make sure to either delete it manually with docker rmi or run docker system prune periodically to remove any accumulated waste.

Roadmap

Planned

  • Add a docker-compose.yml file to environments to handle port bindings, volumes, etc.
  • Change dockerfile template such that user and repository are args, inserted during build instead of when generating the file.
  • Generate unique environment image names for envs that have the same name but are located in different local folders

v0.0.5

  • Add /home/user/.local/bin to $PATH so that installed scripts work.

v0.0.4

  • Automatically deletes untagged images when managing dependencies.
  • Added commands to remove and update dependencies.
  • Added a bunch of exception handling when Docker commands fail.

v0.0.3

  • Improved install script to make it robust to different paths for the python command.

v0.0.2

  • Added a command to install dependencies inside the environment and commit/rebuild the image.

v0.0.1

  • Added commands to create, list, and run a shell inside of environments.

License and Contribution

Code is MIT, and all contributions are appreciated 👋 !

To use pydock in development mode, after you fork and clone, run:

sudo make dev

This will create a soft link in /usr/bin/pydock to your working src/pydock.py file, so that when you type pydock you'll be using your development version.

You might also like...
Python implementation of an automatic parallel parking system in a virtual environment, including path planning, path tracking, and parallel parking
Python implementation of an automatic parallel parking system in a virtual environment, including path planning, path tracking, and parallel parking

Automatic Parallel Parking: Path Planning, Path Tracking & Control This repository contains a python implementation of an automatic parallel parking s

This simple script generates a backup of a given Python and R environment

Python Environment Backup It’s always good to maintain your Python and R Anaconda environment packages properly listed and well-kept in case you have

A full-featured, hackable tiling window manager written and configured in Python
A full-featured, hackable tiling window manager written and configured in Python

A full-featured, hackable tiling window manager written and configured in Python Features Simple, small and extensible. It's easy to write your own la

Windows Task Manager with special features, written in Python.
Windows Task Manager with special features, written in Python.

Killer That damn Chrome ⬇ Download here · 👋 Join our discord Tired of trying to kill processes with the default Windows Task Manager? Selecting one b

Demo of patching a python context manager

patch-demo-20211203 demo of patching a python context manager poetry install poetry run python -m my_great_app to run the code poetry run pytest to te

An extensive password manager built using Python, multiple implementations. Something to meet everyone's taste.
An extensive password manager built using Python, multiple implementations. Something to meet everyone's taste.

An awesome open-sourced password manager! Explore the docs » View Demo · Report Bug · Request Feature 🐍 Python Password Manager 🔐 An extensive passw

PIP Manager written in python Tkinter
PIP Manager written in python Tkinter

PIP Manager About PIP Manager is designed to make Python Package handling easier by just a click of a button!! Available Features Installing packages

Password manager using MySQL and Python 3.10.2

Password Manager Password manager using MySQL and Python 3.10.2 Installation Install my-project with github git clone https://github.com/AyaanSiddiq

RELATE is an Environment for Learning And TEaching
RELATE is an Environment for Learning And TEaching

RELATE Relate is an Environment for Learning And TEaching RELATE is a web-based courseware package. It is set apart by the following features: Focus o

Comments
  • I recommend using the Typer library

    I recommend using the Typer library

    Docs: https://typer.tiangolo.com

    It defines itself as: Typer is a library for building CLI applications that users will love using and developers will love creating. Based on Python 3.6+ type hints.

    opened by leynier 6
Owner
Alejandro Piad
Professor (Instructor) at @matcom, University of Havana and Ph.D. student jointly at U.Alicante. Democratizing ML via @autogoal, working on cNLP at @ehealthkd.
Alejandro Piad
A docker container (Docker Desktop) for a simple python Web app few unit tested

Short web app using Flask, tested with unittest on making massive requests, responses of the website, containerized

Omar 1 Dec 13, 2021
C++ Environment InitiatorVisual Studio Code C / C++ Environment Initiator

Visual Studio Code C / C++ Environment Initiator Latest Version : v 1.0.1(2021/11/08) .exe link here About : Visual Studio Code에서 C/C++환경을 MinGW GCC/G

Junho Yoon 2 Dec 19, 2021
A simple and easy to use Python's PIP configuration manager, similar to the Arch Linux's Java manager.

PIPCONF - The PIP configuration manager If you need to manage multiple configurations containing indexes and trusted hosts for PIP, this project was m

João Paulo Carvalho 11 Nov 30, 2022
Expense-manager - Expense manager with python

Expense_manager TO-DO Source extractor: Credit Card, Wallet Destination extracto

null 1 Feb 13, 2022
Installer, package manager, build wrapper and version manager for Piccolo

Piccl Installer, package manager, build wrapper and version manager for Piccolo

null 1 Dec 19, 2021
A StarkNet project template based on a Pythonic environment

StarkNet Project Template This is an opinionated StarkNet project template. It is based around the Python's ecosystem and best practices. tox to manag

Francesco Ceccon 5 Apr 21, 2022
The docker-based Open edX distribution designed for peace of mind

Tutor: the docker-based Open edX distribution designed for peace of mind Tutor is a docker-based Open edX distribution, both for production and local

Overhang.IO 696 Dec 31, 2022
This is a Docker-based pipeline for preparing sextractor-ready multiwavelength images

Pipeline for creating NB422-detected (ODI) catalog The repository contains a Docker-based pipeline for preprocessing observational data. The pipeline

null 1 Sep 1, 2022
AndroidEnv is a Python library that exposes an Android device as a Reinforcement Learning (RL) environment.

AndroidEnv is a Python library that exposes an Android device as a Reinforcement Learning (RL) environment.

DeepMind 814 Dec 26, 2022
pyToledo is a Python library to interact with the common virtual learning environment for the Association KU Leuven (Toledo).

pyToledo pyToledo is a Python library to interact with the common virtual learning environment for the Association KU Leuven a.k.a Toledo. Motivation

Daan Vervacke 5 Jan 3, 2022