Setting up a Python Training Environment

I have recently started a crash course in Learning Python to brush up on my technical knowledge of the Language. I have made the following notes to help anybody starting out:

The first thing that I did before starting the course was to set up a docker container to learn the language in to be able to easily write and test scripts without affecting my locally installed Python version.

Setting up the Environment:

To start with, I have made a directory locally on my machine to use for Python training – This is /application/python/. I have made a subdirectory within here (/application/python/working) in order to easily be able to transfer files to/from the container.

Within the directory I have made a docker-compose and Dockerfile to create and manage my container images. This will start off as a simple image but as training goes on this will be expanded to install various Python modules and run scripts on starting.

Dockerfile:

FROM python
ADD ./working /working
WORKDIR /working

docker-compose.yml

version: '3'
services:
 python:
  build: .
  container_name: python-training
  volumes:
   - './working:/working/'
  tty: true

Now all that is required is to start the container (Building it from the image) – It is important to run this with the –build flag each time you modify the Dockerfile (Eg to install packages):

docker-compose up -d --build

Connecting to the Environment

In order to connect to the environment – Simply run the below command and you will be within the /working directory within the container.

docker exec -it python-training bash

Once connected, you can run the below to ensure you are on the version of Python that you require:

python --version

Any comments or questions? Get in touch here or Email me at [email protected]