DevOps

for Beginners

Content

  • What is DevOps
  • Devops workflow
  • What is Docker
  • Docker vs VM
  • Demo

What is DevOps ?

DevOps is the practice of operations and development engineers participating together in the entire service lifecycle, from design through the development process to production support.

DevOps Workflow

DevOps Workflow

What is Docker

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package

Docker Architecture

Docker Vs Virtual Machine

Docker Hello-world

Running your first container

sudo systemctl start docker
# This command will start your docker deamon

docker run hello-world 
# This command will run a hello-world container 


docker info 
# This command will give your all information about 
# Your docker installation and evironment

Pull an Alpine Image

Alpine is a micro os with 4MB size it's suitable for tests.we will execute some command inside it.

docker pull alpine:latest

docker run -it alpine sh 

# run : will create and run a container from the 
#        alpine image

# -it : using the interactive mode to execute commands 
#        on the container 
        
# sh  : is the default shell like bash, zsh ..

#inside the container run these commands :
# - cat /etc/os-release
# - apk add git : install a git package 
# - touch file.txt


#you can execute what you want ! 

Create your first Image

We will run a simple server with flask in a docker container, first write the code.

  1.  save it in file : app.py
  2.  run pipreqs . to genarate the requirements.txt file that contain all needed packages

#import required dependencies
from flask import Flask 

#create an instance of the flask object
app = Flask(__name__)


#create a home route 
@app.route("/")
def hello():
    return "Hello My Name is Hatem"


#the main context
if __name__ == "__main__":
    
    #run the app on port 8080 and localhost
    app.run(host="0.0.0.0", port=8080)

Create the Dockerfile

it is a set of instructions that allow us to create the image.

  1.  run :   docker build -t flaskapp .
  2.  run : docker run -p 8080:8080 flaskapp
# use python as a base image that is needed 
# to run any python app
FROM python:latest

# define a work directory
WORKDIR /app

# copy the req.txt to the app folder in the image
COPY requirements.txt .

# install all packages existed inside te file 
RUN pip install -r requirements.txt

# copy the app.y to /app
COPY app.py .

# execute the python script when running the container
CMD python app.py

Hello Docker part I

Hello Docker part II

devops

By hatem ben tayeb

devops

this is a short presentation of devops

  • 882