Using Docker container to develop Flask application

Using Docker container to develop Flask application

Kubernetes

Open source CONTAINER orchestration tool. It has two main components, Control Plane and Data Plane?

Control plane

Key components of a control plane are API server, the etcd data store, the controller manager, the scheduler, and an optional cloud controller manager?

All components of control plane can be hosted on a single node i.e physical machine. Multiple nodes can host different control plane components for fault tolerance and scalability.?

Data plane

Contains worker nodes which are physical machines (or virtual).?

Nodes can have one or more pods. default maximum of 110 Pods per node.?

Pods typically contains one containers application. In rare and advanced use case, one main container is tightly coupled with multiple supporting containers.?

Horizontal Pod Auto-Scaling configuration (HPA) automatically adjusts the number of pod replicas based on CPU utilization, memory usage, or custom metrics.?

Pods are allocated CPU and memory. This can be configured to auto scaled as well.


Docker

The IT software “Docker” is containerisation technology that enables the creation and use of Linux containers.?

The open source Docker community works to improve these technologies to benefit all users.?

The company, Docker Inc., builds on the work of the Docker community, makes it more secure, and supports the improved and hardened technologies for enterprise customers.?

Docker components

  • Docker Client: run, build, pull commands interact with registry?
  • Docker Host: Docker deamon manages images, containers, networks, and volumes?
  • Registry: Docker Hub is a public registry which stores docker images?

Docker desktop software include client, deamon and Kubernetes (inactive by default) etc?

Docker objects

Images, containers, volumes etc?

  • An image is a read-only template with instructions for creating a Docker container.?
  • A container is a runnable instance of an image.?
  • If you want your containers to use or persist data beyond the scope of the container’s lifetime. You can use volumes to solve this problem by working with Docker to mount, create, and share volumes between containers.??


Deployment

Simple Flask web application design include

  1. Nginx is a web server?
  2. Guniconn is web server gateway interface (WSGI)?
  3. Flask is a python web application framework?

Need WSGI to decouple actual python web application tech stack from the web server. PEP 3333 is a standard followed by all WSGI.

Flask containerised application code


Docker commands

Shows active containers.

docker ps        

Shows all containers.

docker ps –a        

Download image from docker hub to create a container and start it?

docker run -it --name <container name> <image name>?

docker run -it --name ubuntu_container01 ubuntu?        

docker pause <container name>?

docker unpause <container name>?

docker stop <container name>?

docker start <container name>?

docker start ubuntu_container01?        

Syntax to remove or delete container.

docker rm <container name>

Note we cannot remove running container without stoping it first.??

Syntax to execute command inside a container.

docker exec <container name> <command>

docker exec ubuntu_container01 ls??        

docker exec –it <container_name> bash?

-it is for Interactive TTY (TeleTYpe)?

docker exec -it ubuntu_container01 bash        

?List images available on local machine.

docker images        

Port mapping between container and host machine.

Docker run –it –p <local_port>:<container_port> <container_name>?

docker run –it –p 1025:1025 ubuntu-container01?        

To build an image create Dockerfile inside project folder and run below commands.

docker build –t <image_name> <path/to/Dockerfile>?

docker build -t test_image .        

Dockerfile

FROM

RUN

COPY

WORKDIR

EXEC

CMD

ENTRYPOINT

Docker compose

To create multiple containers at once create a docker-compose.yaml file in project folder and run below commands in the folder.

Compose yaml file contains images to be downloaded from docker hub, port mapping etc.

docker compose up?-d        

–d is detached mode runs containers in background and lets us use terminal.

docker compose down        


要查看或添加评论,请登录

Azharuddin Mohammad的更多文章

社区洞察

其他会员也浏览了