
What is Docker?
Docker for python– Docker has become one of the demanded technologies in this fast-growing tech era. In simple words, docker can be said as a container. For example, consider a ship that needs to be loaded with goods. It will take a lot of time to load one by one and adjusting it based on the space. Instead, one can take a container load everything in the container and just place the container on the ship. This will reduce your time, space, and labor too. The same reasons are behind the usage of docker. By using a docker, one can solve dependency conflicts i.e. version conflicts of software won’t occur, can easily scale up i.e. it handles the issue of single server facing higher usage problem, etc.
Writing a docker file:
The standard 5 commands used in dockerfile are:
- FROM
- WORKDIR
- COPY
- RUN
- CMD
Example :
FROM python: 3.6
WORKDIR /app
COPY src/requirements.txt ./
RUN pip install -r requirements.txt
COPY src /app
CMD[“python”,”appfile.py”]
Explanation:
FROM “base image” – this specifies which python image has to be used as the base image
WORKDIR “working directory” – specifies the location of the working directory
COPY “source” “destination” – copies the contents from the source file to the destination file
RUN “pip install requirements” – runs the installation of all the requirements for the application
COPY “source” “destination” – copies all the installation from the source to the destination which is the working directory
CMD[“technology”,”entrypoint”] – specifies which technology is used i.e. in this case it is python and the entrypoint specifies the python file which acts as the entrypoint to run the application
If you are writing a python dockerfile for a web application you can also use “EXPOSE” command in the dockerfile.
EXPOSE “portnumber” – specifies the portnumber in which the localhost must run in the browser
Building a docker image:
docker build -t docker-image
docker run –rm docker-image
The above commands are used to build the image and run the dockerfile for your application.
Hers, -t is specified in front of the desired image. An image can be created without specifying a name. The image is always created with an auto-generated unique ID, thus making it an optional parameter.
And, –rm is specified near the run command. This ensures that the container that has been created is automatically deleted once it has stopped.
This post is contributed by Kushmitha Radhakrishnan.
Read More:
Hello World in 35 Programming Languages
A timeless custom known as the “Hello, World!” program marks the start of every programmer’s adventure in the wide world of programming. This surprisingly easy article examines the various ways that 35 different programming languages express this well-known statement. Every “Hello, World!” implementation offers a glimpse into the distinct syntax and personality of the language…
How to Scrape Data From Any Website with Python?
Suppose you’re a stock market analyst and want to keep a finger on the pulse of financial news. What would you use to extract this information? Web scraping! It makes the process easier. With Python, you can automate the extraction of headlines and insights from multiple news websites, helping you make more informed decisions in…
Continue Reading How to Scrape Data From Any Website with Python?
Become Job Ready With Free Harvard Computer Science course: Enroll Now
Introduction Hello friends, welcome to my blog, today, I will show you a free computer science course in which you or anyone can enroll and directly learn from the best educators and one of the best universities in the world i.e. Harvard. This course is free and covers all the basic topics and technologies required…
Continue Reading Become Job Ready With Free Harvard Computer Science course: Enroll Now
Free Python Certification course from Alison: Good for Resume
Hello friends, welcome again to my website, today, I will share a Python course with you where you can get a free certificate, yes, completely free. Alison, one of the world’s most famous platforms, provides a free Python certificate to anyone who completes their free Python course. This course is for complete beginners i.e. for…
Continue Reading Free Python Certification course from Alison: Good for Resume
Download 1000+ Projects, All B.Tech & Programming Notes, Job, Resume & Interview Guide, and More – Get Your Ultimate Programming Bundle!
Introduction Hello friends and welcome again today, I will give you something that will help you throughout your programming journey, no matter whether you are starting our or an experienced guy who is looking to increase his salary. Today, I am going to share with you a programming bundle under which you will find these…
Udacity Giving Free Python Course: Here is how to Enroll
Hello friends, welcome again, in this article, I will show you an outstanding Python course available on a worldwide famous platform i.e. Udacity, and the surprising thing is that it’s completely free. This course is beginner’s friendly and is of 14 hours duration with no prerequisites to enroll, you need to go to the website…
Continue Reading Udacity Giving Free Python Course: Here is how to Enroll