Streamlining Two-Tier Application Deployment with Docker

Streamlining Two-Tier Application Deployment with Docker

Effective Image and Container Management

ยท

2 min read

Hello Everyone..... ๐Ÿ™๐Ÿ™๐Ÿ™ Good Day

After learning about Docker and its concepts, I am setting up my first two-tier application using Docker. This application runs on Flask and uses MongoDB for the database.

Table of Content

  1. Create an image of the application

  2. Create a custom network for the application

  3. Create a container from the image

  4. Enter into the container

  5. Check Status

    1. Create an image of the application

ubuntu@ip-172-31-35-51:~/microservices-k8s/flask-api$ docker build . -t simple_app

ubuntu@ip-172-31-35-51:~/microservices-k8s/flask-api$ docker images
REPOSITORY   TAG         IMAGE ID       CREATED         SIZE
simple-app   latest      9eaaa438aae2   7 seconds ago   125MB
python       alpine3.7   00be2573e9f7   5 years ago     81.3MB

2. Create a network for an application

docker network create simple-app-net

ubuntu@ip-172-31-35-51:~/microservices-k8s/flask-api$ docker network create simple-app-net
7a97e7bc22946f03a77eb41c9f8be37edae71dd5bfa744887577a72e579d6f3b
buntu@ip-172-31-35-51:~/microservices-k8s/flask-api$ docker network ls
NETWORK ID     NAME             DRIVER    SCOPE
60edcb5311e6   bridge           bridge    local
2d84da749977   host             host      local
f83509cdaa43   none             null      local
7a97e7bc2294   simple-app-net   bridge    local

Here new custom network for our project is added successfully.

3. Now we will create a container which runs in a new custom network

docker run -d -p 5000:5000 --name simple-app-container --network simple-app-net simple-app:latest

ubuntu@ip-172-31-35-51:~/microservices-k8s/flask-api$ docker ps
CONTAINER ID   IMAGE               COMMAND           CREATED          STATUS          PORTS                                       NAMES
5edddfd889cb   simple-app:latest   "python app.py"   39 seconds ago   Up 38 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   simple-app-container

We can see that the application is running on port 5000.

4. Enter into the container

docker exec -it 5edddfd889cb sh

ubuntu@ip-172-31-35-51:~/microservices-k8s/flask-api$ docker exec -it 5edddfd889cb sh
/app #

Let's check if the container can communicate with the outside world using the ping command.

/app # ping google.com
PING google.com (216.58.203.14): 56 data bytes
64 bytes from 216.58.203.14: seq=0 ttl=53 time=21.827 ms
64 bytes from 216.58.203.14: seq=1 ttl=53 time=21.799 ms
64 bytes from 216.58.203.14: seq=2 ttl=53 time=21.859 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 21.799/21.828/21.859 ms
/app #

Yes, the container can communicate with the outside world.

To summarize this tutorial, I learned how to create a Docker container with a custom network and add the container to that network.

ย