top of page

Containerization

Updated: 16 hours ago

Docker Zoo to understand containerization



Run 3 tiny web apps (Cat, Dog, Cow) in separate containers and see how containerization isolates them.


Folder setup

Create a folder for your project:

md docker-zoo
cd docker-zoo

Cat App

Create a new folder:

md cat
cd cat
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return "Hi, I’m the Cat app! I live inside my own Docker container."

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=4001)

requirements.txt

flask

Dockerfile

FROM python:3.9-slim
WORKDIR /code
COPY . .
RUN pip install -r requirements.txt
EXPOSE 4001
CMD ["python", "app.py"]

Dog App

Go back and make another folder:

cd ..
md dog
cd dog
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return "Woof! The Dog app is barking happily inside its Docker container."

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=4002)

requirements.txt

flask

Dockerfile

FROM python:3.9-alpine
WORKDIR /project
COPY . .
RUN pip install -r requirements.txt
EXPOSE 4002
CMD ["python", "app.py"]

Cow App

cd ..
cd cow
cd cow
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return "Moo! The Cow app is grazing peacefully inside its own container."

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=4003)

requirements.txt

flask

Dockerfile

FROM python:3.9-slim
WORKDIR /workspace
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 4003
CMD ["python", "app.py"]

Build all images

From main docker-zoo/ directory:

docker build -t cat-service ./cat
docker build -t dog-service ./dog
docker build -t cow-service ./cow

Run all containers

docker run -d -p 4001:4001 cat-service
docker run -d -p 4002:4002 dog-service
docker run -d -p 4003:4003 cow-service

$50

Product Title

Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button

$50

Product Title

Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button.

$50

Product Title

Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button.

Recommended Products For This Post
 
 
 

Recent Posts

See All

Comments


© 2023 by newittrendzzz.com 

  • Facebook
  • Twitter
  • Instagram
bottom of page