Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views3 pages

Docker

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

Docker

 Docker is used to containerize the applications to solve system compatibility issues.

 Docker creates images of the application so that it can run on


different OSs with different configurations.

 How it does it is that it follows these steps: Flask, Flasgger


st
1. First of all, it creates a base image 1 (i.e., Linux: Ubuntu)
Anaconda: Python 3._
from the docker hub.
environment
The base image talks about the basic OS we want. A base
image in Docker is a crucial building block for creating Linux, Ubuntu Version
containerized applications. It provides a reliable, efficient,
and secure foundation on which you can layer your application
Base Image
code and configurations, making it easier to develop, deploy, and
manage containerized applications across different environments.

Base images are essentially pre-built and pre-configured images of an operating


system or a specific software stack that provide a foundation for your own
application or service.

Common base images include those based on popular Linux distributions like
Ubuntu, CentOS, or Alpine Linux. Additionally, there are specialized base images for
various programming languages, frameworks, and applications, which can save you
even more time when containerizing specific types of software.

2. Next, we stack a component atop of base image where we specify the environment
we will work with; in this case, it is Anaconda: Python 3.x.

3. Then we stack the component where we can mention all the required python
packages; ones we have used in our app (like Flask, Flasgger, Pandas, NumPy)

4. Now, once we put together all the components we require, we will encapsulate the
containers together and that will be the docker image.

 These are the commands it will use: Docker Image


1. FROM: This is used to create the base
image. Flask, Flasgger

Anaconda: Python 3._ Components


2. COPY: This is used to create the user root
environment
folder in docker.
When we create an app in the host system Linux, Ubuntu Version Dockerized
(the system that we create the app with), weContainer
will have a folder structure where all the
components of the app will be present. Base Image
Using this ‘COPY’ we will be able to duplicate this folder structure from host system
into the user root folder inside the docker container as well.

3. EXPOSE: Each and every docker image has a network interface. So, we expose the
network interface of this docker image so that we can access the web app inside the
docker image. The common network interface would be: 5000/8000.

Docker 1
4. WORKDIR: Now, if the working directory in the host system is like:
Money:/…../…../
Where, ‘Money’ is the base folder in the host system, then we should also
know in the docker container, from where we will initialize the app. We can
take the working directory in the Docker as: user/python/local

5. RUN: We may need to install all the libraries that we used in the app in the host
system in the docker image as well. Therefore, we create the requirements.txt file
and mention all the libraries that we require. Then we use the command:
pip install -r requirements.txt

6. CMD: If we look at the local host systems’ files of the app, there will be a file called:
‘app.py’. This will be the point of initialization for the entire app. To execute this file,
we will use: ‘python app.py’ in the python terminal.

Similarly, in order to run the docker image, we will use the file(‘app.py’) inside
‘user/python/local’, and we will write the command: ‘python app.py’ there as well
to execute the docker image.
Here, the . represents the current working
 Steps:
directory
1. Write the Docker file
2. Building the docker image
-t is used to tell Docker to tag the docker
3. Running the app (money authenticator app)
container in the name: money_api

Build the docker image:


-p is used to publish the container's port to
docker build -t money_api .
the host. Here, “-p 8000:8000” is specifying
that port 8000 on the host should be
See the dockers
mapped to port 8000 on the container.
docker ps -a
Run the docker:
docker run -p 8000:8000 money_api
- This is the base image. It is popular
because it installs some of the
 Create/write the docker file in the working
library/package dependencies
directory in the host system. It should have the
automatically (like sklearn, etc.)
following commands in it:
FROM continuumio/anaconda3:4.4.0
- The . in COPY denotes working
COPY . /usr/app/
directory of local host system.
EXPOSE 8000
/usr/app denotes user root folder in
WORKDIR /usr/app/
docker image. Hence, we are
RUN pip install -r requirements.txt
copying the files from host system
CMD python app.py
into docker image.
- We are then exposing 5000 as the
n/w interface

- Working directory will be the same


as in COPY’s second statement The requirements.txt
(/user/app/) file will have the
following libraries
- Then we run the pip install -r listed along with their
requirements.txt command to install versions:
all the required libraries.

- Finally, we execute the CMD to run


the app.
Docker 2

Docker 3

You might also like