Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Becoming DevOps — Docker

Becoming DevOps — Docker

Docker

Introduction

In this guide to Becoming DevOps we will look at what a DevOps engineer should know to be an expert and what some of the requirements are for many companies.

We will talk about:

  1. Terraform
  2. Container Registry
  3. Kubernetes
  4. Docker (this one)
  5. Deploying an application on Kubernetes
  6. Analyze infrastructure as code (IaC)
  7. CI/CD with GitHub Action
  8. Kube-Prometheus & Observability
Our stack is deployed and hosted in Azure and automated with Terraform.

Docker

Docker is a containerization platform that enables you to package applications into containers. The package becomes an isolated environment, containing everything the app needs to run.

The underlying system — the host — is abstracted from the application itself. This is important because it circumvents dependency nightmares. If you develop an application on one machine and deploy it to a QA machine, if there are any differences in their dependencies, your application might not function in that environment, despite being a perfectly workable app.

Some of things you need to know about Docker:

  • Containerization and virtualization
  • Write Dockerfiles
  • Docker Compose
  • How to build / run / push containers
  • Network and Volumes
  • Docker Hub

If you want to know more about what Docker is and how it work, just watch this video.

Creating the Docker image

Now we will create a Docker image to containerize a Python application. It’s a very simple application that will print “Hello, World! Welcome to A Practical Guide to Observability in DevOps”.

from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
  return 'Hello, World! Welcome to the Becoming DevOps guide'
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)

The Dockerfilelooks like this:

FROM python:3.7-alpine
WORKDIR /app
COPY requirements.txt /app
RUN pip3 install -r requirements.txt
COPY . /app
EXPOSE 5000
CMD ["python", "app.py"]

The requirements.txt:

Flask==2.1.0

Create the image and run it locally to confirm that it works.

docker build -t pythonapp .

List the image with docker images

Run it locally to see that it works

docker run -itd -p 8000:5000 pythonapp

Now, open a browser and go to : http://127.0.0.1:8000/

You can also test it using curl

curl http://localhost:8000

Hello, World! Welcome to the Becoming DevOps guide!

Great, our docker image works.

Let’s now see how we can push it to our Azure ACR that we deployed earlier in part 2.

Push an image to Azure ACR

In part 2, we deployed an Azure ACR (using Terraform). Then we verified that we could login to the ACR with the az acrcommand.

Now, we will store the our image (pythonapp) in our Azure Container Registry.

First, you need to log in to ACR with Azure CLI:

az acr login --name demolab123acr
>> Login Succeeded

Next step is to tag the Docker image:

docker tag pythonapp demolab123acr.azurecr.io/pythonapp:v1

If you now type docker images you will see our new (tagged) image.

demolab123acr.azurecr.io/pythonapp

Finally, you can push the Docker image to ACR

docker push demolab123acr.azurecr.io/pythonapp:v1

Verify that the image is in Azure ACR

We can now verify that our image is pushed to the Azure Container Registry, by using the az acrcommand.

az acr repository list --name demolab123acr.azurecr.io

The output should look like this:

[
"pythonapp"
]

Conclusion

That is it for part 4. We first looked at Docker . After that, we created and dockerized a simple python application. We then tagged it, and pushed the docker image to our Azure Container Registry.

In the next part, we will deploy an application to our Azure Kubernetes Service (AKS) cluster using this image.

If you found this useful, please hit that clap button and follow me to get more articles on your feed.

If you find this helpful, please click the clap 👏 button below a few times to show your support for the author 👇

🚀Join FAUN & get similar stories in your inbox each week


Becoming DevOps — Docker was originally published in FAUN Publication on Medium, where people are continuing the conversation by highlighting and responding to this story.

Share the post

Becoming DevOps — Docker

×

Subscribe to Top Digital Transformation Strategies For Business Development: How To Effectively Grow Your Business In The Digital Age

Get updates delivered right to your inbox!

Thank you for your subscription

×