Let’s set up Python interpreter inside a docker container.
It is required that docker is installed in the base operating system. So we can run a docker container.
Here I am running a docker container with some name ‘pyos’ using centos docker image and also I am attaching a volume to this container (a directory created in base OS). So when the container is created a directory will be created inside it (here I used same name /pyfiles or we use some existing path) and will be linked to directory in the base OS (/pyfiles).
If we put any file or change something inside /pyfiles (in base OS) it will be reflected in /pyfiles (inside the container)
docker container run -it --name pyos -v /pyfiles:/pyfiles centos
Now, we are inside the docker container. Lets install python3 here,
So, it is installed and we can see it is running perfectly.
Let’s exit this container now,
We are back to the base OS and I am adding a small python code inside the /pyfiles directory which is attached to our container.
Let’s again start our container which we exited and execute the code we just created,
docker exec pyos <give command>
So, it is working fine and we have done the setup successfully.