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
Cvdl-hw2 - Find Contour, Camera Calibration, Augmented Reality and Stereo Disparity Map

opevcvdl-hw2 This project uses openCV and Qt to achieve the requirements. Version Python 3.7 opencv-contrib-python 3.4.2.17 Matplotlib 3.1.1 pyqt5 5.1

Kenny Cheng 3 Aug 17, 2022
Start and stop your NiceHash miners using this script.

NiceHash Mining Scheduler Use this script to schedule your NiceHash Miner(s). Electricity costs between 4-9pm are high in my area and I want NiceHash

SeaRoth 2 Sep 30, 2022
kodi addon 115网盘

plugin.video.115 kodi addon 115网盘 插件,需要kodi 18以上版本,原码播放需配合 https://github.com/feelfar/115proxy-for-kodi 使用 安装 HEAD 由于release包尚未释出,可直接下载源代码zip包

109 Dec 29, 2022
List Less Than Ten with python

List Less Than Ten with python

PyLaboratory 0 Feb 07, 2022
It's an .exe file that can notify your chia profit and warning message every time automatically.

chia-Notify-with-Line 警示程式 It's an .exe file that can notify your chia profit and warning message every time automatically. 這是我自行設計的小程式,有轉成.exe檔了,可以在沒

You,Yu 1 Oct 28, 2021
Lectures for Udemy - Complete Python Bootcamp Course

Complete-Python-Bootcamp Welcome to the Repository for the Complete Python Bootcamp! This is the Repository for the Udemy course - "Complete Python Bo

Marci 2k Dec 28, 2022
Add-In for Blender to automatically save files when rendering

Autosave - Render: Automatically save .blend, .png and readme.txt files when rendering with Blender Purpose This Blender Add-On provides an easy way t

Volker 9 Aug 10, 2022
Заглушки .NET библиотек для IronPython

Код репозитория основан на ironpython-stubs. Выражаю gtalarico бесконечную благодарность за вклад в развитие сообщества разработчиков скриптов и плаги

12 Nov 23, 2022
Add your recently blog and douban states in your GitHub Profile

Add your recently blog and douban states in your GitHub Profile

Bingjie Yan 4 Dec 12, 2022
Um Script De Mensagem anonimas Para linux e Termux Feito em python

Um Script De Mensagem anonimas Para linux e Termux Feito em python feito em um celular

6 Sep 09, 2021
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
Insert a Spotify Playlist, Get a list of YouTube URLs from it.

spotbee This is a module that spits out YouTube URLs from Spotify Playlist URLs Why use this? It is asynchronous which makes it compatible to use with

Nishant Sapkota 10 Apr 06, 2022
This is a simple leaderboard for 30 days of Google Cloud program for students of ASIET

30daysleaderboard #Hacktoberfest - Please don't make changes in readme file. Only improvement in the project will be accepted. Update - Now if you run

5 Oct 29, 2021
py-js: python3 objects for max

Simple (and extensible) python3 externals for MaxMSP

Shakeeb Alireza 39 Nov 20, 2022
Groupe du projet Python en 2TL2-4

Présentation Projet EpheCom Ce logiciel a été développé dans le cadre scolaire. EpheCom est un logiciel de communications - vocale et écrite - en temp

1 Dec 26, 2021
《practical python programming》的中文翻译

欢迎光临 大约 25 年前,当我第一次学习 Python 时,发现 Python 竟然可以被高效地应用到各种混乱的工作项目上,我立即被震惊了。15 年前,我自己也将这种乐趣教授给别人。教学的结果就是本课程——一门实用的学习 Python的课程。

编程人 125 Dec 17, 2022
Connect Playground - easy way to fill in your account with production-like objects

Just set of scripts to initialise accpunt with production-like data: A - Basic Distributor Account Initialization INPUT Distributor Account Token ACTI

CloudBlue 5 Jun 25, 2021
→ Plantilla de registro para Python

🔧 Pasos Necesarios CMD 🖥️ SOCKETS pip install sockets 🎨 COLORAMA pip install colorama 💻 Código register-by-inputs from turtle import color # Impor

Panda.xyz 4 Mar 12, 2022
Cross-platform .NET Core pre-commit hooks

dotnet-core-pre-commit Cross-platform .NET Core pre-commit hooks How to use Add this to your .pre-commit-config.yaml - repo: https://github.com/juan

Juan Odicio 5 Jul 20, 2021