
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:
Top 25 Pattern Programs in C++
In this article, I will show you the Top 25 Pattern Programs in C++ that you must learn which will help you to understand the usage of nested loops. We will learn to create different geometrical shapes like Squares, triangles, Rhombus, etc. We have provided the code as well as output for all the patterns…
Currency Converter in C++
In this article, we will build a simple program for Currency Converter in C++. The user will be able to convert currencies like Dollar, Euro, Pound, and Rupee. This is a console application and very simple to understand as we only use a bunch of conditionals to write the entire program. Features Users can convert…
SQLite | CRUD Operations in Python
CRUD stands for Create Read Update Delete. I will show you how to perform CRUD Operations in Python. You need basic Tkinter and SQLite knowledge before you read further. This app is straightforward, when you will open this app, a GUI with 4 green colored buttons will open to perform CRUD(create read update delete) operations.…
Number Guessing Game in C++
In this article, we will build a simple Number Guessing Game in C++. It’s a game in which the player has to guess a secret number in a range that is generated by the computer and upon a wrong guess by the player, the game will give hints to the player to guess the correct…
Image background remover in Python
Hello friends, in this article, we will learn how to create an Image background remover in Python. I will first show you a simple program and then you will see a smile GUI made using tkinter. We need to install rembg, you can install rembg using the pip command: pip install rembg Image background remover…
C++ Project Structure
Hello everyone, have you ever wondered while looking inside a big C++ project structure what are these different folders, subfolders, and files used for? Especially when we have just started working with C++ we get lots of questions and confusion regarding this. So let’s talk about the C++ Project Structure of a general application. Whenever…