A simple python contaner spawning the python 3 version for python app development. It boostraps the virtualenv and automatically installs all the required pip dependencies.
The folder /home/developer/code
is being exported as volume. Also you can set the setting PROJECT_PATH
to .env
in order to specify the path that will be mounted as volume.
Also the following enviromental variables are used:
Name | Default Value | Purpoce |
---|---|---|
DOCKER_UID |
1000 | Use that to change the user id on the fly. Usefull for multi-user environments |
DOCKER_GID |
1000 | Use that to change the user group id on the fly. Usefull for multi-user environments |
DEPENDENCIES_FILE |
N/A | File that is generated via pip freeze and contains your project's dependencies. NOTE: The path is assumed relatively to the source code root. |
DEV_HOME |
"/home/developer" | Home of the in-container developer account. |
DEV_SRC_PATH |
"${DEV_HOME}/code" | Location that will be mounted as volume and contains the project's source code |
VENV_FOLDER |
env | The name of the virtual environment. |
I would reccomend creating the following docker-compose.yml to your project's root
version: '3'
services:
python_dev:
image: pc-magas/python_dev:3
stdin_open: true
tty: true
volumes:
- $PROJECT_PATH:/home/developer/code
environment:
- DEPENDENCIES_FILE=$DEPENDENCIES_FILE
Then create this .env
file:
PROJECT_PATH=^path_file^
DEPENDENCIES_FILE=^dependencies_file^
Where ^path_file^
is the project's root and ^dependencies_file^
is the pip freeze
generated file.
In case that the user is or the default users group is NOT 1000
use the following docker-compose.yml
:
version: '3'
services:
python_dev:
image: pc-magas/python_dev:3
stdin_open: true
tty: true
volumes:
- $PROJECT_PATH:/home/developer/code
environment:
- DEPENDENCIES_FILE=$DEPENDENCIES_FILE
- DOCKER_UID=$UID
- DOCKER_GID=$GID
And generate the .env
like that:
cd ^path_file^
echo "PROJECT_PATH"=$(pwd) >> .env
echo "UID="$(id -u) >>.env
echo "UID="$(id -g) >>.env
echo "DEPENDENCIES_FILE=^depndencies_file^" >>.env
Where on the commands above the ^path_file^
is the project's root and ^dependencies_file^
is the pip freeze
generated file.
Then via the following command you can launch it:
docker-compose run python_dev
Do not be alarmed by the follwing errors during container launch:
bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell bash: cd: too many arguments
Copywright Dimitrios Desyllas
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
Python is delivered with itsd own licence.