pydock - Docker-based environment manager for Python

Related tags

Miscellaneouspydock
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.

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
Multiperiod Reports by Month/Quarter/Year in Beancount.

Multiperiod Reports by Month/Quarter/Year in Beancount. Plotting income and expenses over time. Treemap plot of expenses.

Altynbek Isabekov 16 Aug 13, 2022
Penelope Shell Handler

penelope Penelope is an advanced shell handler. Its main aim is to replace netcat as shell catcher during exploiting RCE vulnerabilities. It works on

293 Dec 30, 2022
Dump Data from FTDI Serial Port to Binary File on MacOS

Dump Data from FTDI Serial Port to Binary File on MacOS

pandy song 1 Nov 24, 2021
Python library to decorate and beautify strings

outputformater Python library to decorate and beautify your standard output 💖 I

Felipe Delestro Matos 259 Dec 13, 2022
Direct Multi-view Multi-person 3D Human Pose Estimation

Implementation of NeurIPS-2021 paper: Direct Multi-view Multi-person 3D Human Pose Estimation [paper] [video-YouTube, video-Bilibili] [slides] This is

Sea AI Lab 253 Jan 05, 2023
Hacktoberfest 2021 contribution repository✨

🎃 HacktoberFest-2021 🎃 Repository for Hacktoberfest Note: Although, We are actively focusing on Machine Learning, Data Science and Tricky Python pro

Manjunatha Sai Uppu 42 Dec 11, 2022
synchronize projects via yaml/json manifest. built on libvcs

vcspull - synchronize your repos. built on libvcs Manage your commonly used repos from YAML / JSON manifest(s). Compare to myrepos. Great if you use t

python utilities for version control 200 Dec 20, 2022
A carrot-based color palette you didn't know you needed.

A package to produce a carrot-inspired color palette for python/matplotlib. Install: pip install carrotColors Update: pip install --upgrade carrotColo

10 Sep 28, 2021
Zapiski za ure o C++-u

cpp-notes Zapiski o C++-u. Objavljena verzija je na https://e6.ijs.si/~jslak/c++/ Generating the notes The setup assumes you are working in a Linux en

Jure Slak 1 Jan 05, 2022
MiniJVM is simple java virtual machine written by python language, it can load class file from file system and run it.

MiniJVM MiniJVM是一款使用python编写的简易JVM,能够从本地加载class文件并且执行绝大多数指令。 支持的功能 1.从本地磁盘加载class并解析 2.支持绝大多数指令集的执行 3.支持虚拟机内存分区以及对象的创建 4.支持方法的调用和参数传递 5.支持静态代码块的初始化 不支

keguoyu 60 Apr 01, 2022
A Bot Which Can generate Random Account Based On Your Hits.

AccountGenBot This Bot Can Generate Account With Hits You Save (Randomly) Keyfeatures Join To Use Support Limit Account Generation Using Sql Customiza

DevsExpo 30 Oct 21, 2022
A(Sync) Interface for internal Audible API written in pure Python.

Audible Audible is a Python low-level interface to communicate with the non-publicly Audible API. It enables Python developers to create there own Aud

mkb79 192 Jan 03, 2023
Animation retargeting tool for Autodesk Maya. Retargets mocap to a custom rig with a few clicks.

Animation Retargeting Tool for Maya A tool for transferring animation data between rigs or transfer raw mocap from a skeleton to a custom rig. (The sc

Joaen 62 Dec 19, 2022
sfgp is a package that aggregates individual scripts and notebooks, primarily written for the basic analysis tasks of genetics and pharmacogenomics data.

sfgp is a package that aggregates individual scripts and notebooks, primarily written for the basic analysis tasks of genetics and pharmacogenomics data.

Vishal Sarsani 1 Mar 31, 2022
A small script I made that takes any standard Decklist of magic the gathering cards and pulls all card images from scryfall at once!

A small script I made that takes any standard Decklist of magic the gathering cards and pulls all card images from scryfall at once!

15 Aug 26, 2022
⏰ Shutdown Timer is an application that you can shutdown, restart, logoff, and hibernate your computer with a timer.

Shutdown Timer is a an application that you can shutdown, restart, logoff, and hibernate your computer with a timer. After choosing an action from the

Mehmet Güdük 5 Jun 27, 2022
mypy plugin for PynamoDB

pynamodb-mypy A plugin for mypy which gives it deeper understanding of PynamoDB (beyond what's possible through type stubs). Usage Add it to the plugi

1 Oct 21, 2022
A collection of simple tools that proved to be needed for hadling large periodic calculations with the VASP software package.

VESTA-tools A collection of simple tools that proved to be needed for handling large periodic calculations with the VASP software package. distTotCalc

Ilia Kichev 2 Dec 14, 2021
A comprensive software collection for nmea manipulation

nmeatoolkit A comprensive software collection for nmea manipulation; it includes a library and a collections of command line tools. Library pipes: con

Davide Gessa 1 Sep 14, 2022
All kinds of programs are accepted here, raise a genuine PR, and claim a PR, Make 4 successful PR's and get the Stickers and T-Shirt from hacktoberfest 2021

this repository is excluded from hacktoberfest Hacktoberfest-2021 This repository aims to help code beginners with their first successful pull request

34 Sep 11, 2022