Python on Docker !!!

What is Docker?

Divyanshu Sharma
4 min readNov 19, 2020

Docker is an open-source tool that automates the deployment of an application inside a software container. Docker provides the ability to package and run an application in a loosely isolated environment called a container. The isolation and security allow you to run many containers simultaneously on a given host. … This means you can run more containers on a given hardware combination than if you were using virtual machines.

Why docker?

Traditionally, virtual machines were used to avoid this unexpected behavior. The main problem with VM is that an “extra OS” on top of the host operating system adds gigabytes of space to the project. Most of the time your server will host several VMs that will take up even more space. And by the way, at the moment, most cloud-based server providers will charge you for that extra space. Another significant drawback of VM is a slow boot.

Docker eliminates all the above by simply sharing the OS kernel across all the containers running as separate processes of the host OS.

Installing Docker :

You can install docker by using “ yum”. Create a new yum repository of docker in yum.repos.d. Paste the docker URL inside the repository with additional gpcheck=0

Use the command yum install docker -ce -y — nobest

Check the docker status using the following command.

Use the command docker pull centos/docker pull ubuntu. Pull the container before using it. Check the availability in the Docker hub.

Docker Hub — a registry with a web interface provided by Docker Inc. It stores a lot of Docker images with different software. Docker Hub is a source of the “official” Docker images made by the Docker team or in cooperation with the original software manufacturer

Image — the basic element for every container. When you create an image, every step is cached and can be reused (Copy On Write model). Depending on the image, it can take some time to build. Containers, on the other hand, can be started from images right away.

Container — a running instance that encapsulates the required software. Containers are always created from images. A container can expose ports and volumes to interact with other containers or/and the outer world. Containers can be easily killed/removed and re-created again in a very short time. Containers don’t keep state.

Use the command to see the available images in docker.

docker images

Use the following command to run a new container. docker run -it — name <anyname> centos . You can see a terminal appears with a different id. this is the docker container you launched.

Installing python on the container :

Install python interpreter using yum command. You can hence run the commands of python here.

If python doesn't install use python36

You can exit the interpreter using exit()

You can exit the docker container by “exit”

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Divyanshu Sharma
Divyanshu Sharma

Written by Divyanshu Sharma

Are you reading ? Cause I am writing :)

No responses yet

Write a response