4. Pre-Concepts
âą DevOps = âDevelopmentâ + âOperationsâ
A set of practices intended to reduce the time
between committing a change to a system and
the change being placed into normal production,
while ensuring high quality
âDevOps: A Software Architect's Perspective.(2015)â
5. Pre-Concepts
âą A Sample of DevOps Tool Chain
â Coding development, review, source management
â Building continuous integration tools, build status
â Testing continuous testing tools
â Packaging artifact repository, application pre-deployment
staging
â Releasing change management, release approvals,
release automation
â Configuring infrastructure configuration and
management, infrastructure as code tools
â Monitoring applications performance monitoring, end-
user experience
There are other (similar but different) chains presented for DevOps Tools.
7. Pre-Concepts
âą Continuous integration (CI)
â The practice of merging all developer working copies to a shared
mainline several times a day
âą Continuous delivery (CD or CDE)
â A software engineering approach to produce software in short cycles,
ensuring that the software can be reliably released at any time. It
includes building, testing, and releasing software with greater speed
and frequency
âą Microservice
â A Software Architecture that structures an application as a collection
of loosely coupled services.
9. Concepts
âą Containerization
â The use of Linux containers to deploy applications
âą Flexible
âą Lightweight
âą Interchangeable
âą Portable
âą Scalable
âą Stackable
10. Concepts
âą Image:
â An executable package that includes everything
needed to run an application--the code, a
runtime, libraries, environment variables, and
configuration files
âą Container:
â A runtime instance of an image
19. Install Docker
Use This link to install Docker on Ubuntu :
https://docs.docker.com/install/linux/docker-ce/ubuntu/
20. Install Docker
Use This link to install Docker on Ubuntu :
https://docs.docker.com/install/linux/docker-ce/ubuntu/
Easiest Way:
1. Go to https://download.docker.com/linux/ubuntu/dists/, choose your
Ubuntu version, browse to pool/stable/,
choose amd64, armhf, arm64, ppc64el, or s390x, and download
the .deb file for the Docker CE (Community Edition) version you want to
install.
2. Install Docker CE
sudo dpkg -i /path/to/package.deb
21. Install Docker
Use This link to install Docker on Ubuntu :
https://docs.docker.com/install/linux/docker-ce/ubuntu/
Easiest Way:
1. Go to https://download.docker.com/linux/ubuntu/dists/, choose your
Ubuntu version, browse to pool/stable/,
choose amd64, armhf, arm64, ppc64el, or s390x, and download
the .deb file for the Docker CE (Community Edition) version you want to
install.
2. Install Docker CE
sudo dpkg -i /path/to/package.deb
Docker has 3 types of updates:
Stable latest stable releases.
Test pre-release, not tested.
Nightly latest builds of main line, in progress for the next major release.
22. Start!
Check you Docker version and Info:
$ docker --version
Docker Version
$ docker info
A Brief of Containers and Images and other stats
23. Hello World!
You can create and run a container from hello-world image, which is pulled
from Docker Hub.
$ docker run hello-world
Read the output! It is important!
24. Hello World!
You can create and run a container from hello-world image, which is pulled
from Docker Hub.
$ docker run hello-world
Read the output! It is important!
27. Get Lists
Docker ps
Get list of running containers
-a Show all containers (stopped or running)
-q Only numeric IDs.
--format Format the output. Samples:
--format "{{.ID}}: {{.Command}}"
--format "table {{.ID}}t{{.Labels}}"
Docker images
Get list of images [on your local machine]
28. docker build --tag=myImage:v0.0.1 ./
Build a new image with name=âmyImageâ and tag=âv0.0.1â from
current directory.
There should be a `DockerFile` in current directory which defines the
new image.
Build An Image
29. docker build --tag=myImage:v0.0.1 ./
Build a new image with name=âmyImageâ and tag=âv0.0.1â from
current directory.
There should be a `DockerFile` in current directory which defines the
new image.
Build An Image# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Set proxy server
ENV http_proxy host:port
ENV https_proxy host:port
# Run app.py when the container launches
CMD ["python", "app.py"]
DockerFile
30. docker run -d -p 4000:80 --name myContainer myImage
Build and star a new container from âmyImageâ.
-p 4000:80 Publish port 80 on container and connect it to port 4000 on localhost.
-d Start the container on detached mode.
--name myContainer Set the container name to âmyContainerâ
Run The App
localhost
myContainerherContainertheirContainer
4000
80
31. docker run -d -p 4000:80 --name myContainer myImage
Build and star a new container from âmyImageâ.
-p 4000:80 Publish port 80 on container and connect it to port 4000 on localhost.
-d Start the container on detached mode.
--name myContainer Set the container name to âmyContainerâ
Run The App
localhost
myContainerherContainertheirContainer
4000
80
You can use `docker create` just like docker run. The difference is that `docker
create` wonât start the container after creating it, but `docker run` will.
32. CMD and Args: Put your CMD and Args after the image name
docker run -d myImage /app/run.sh -c
EXPOSE: Expose ports, additional to those exposed by image defaults.
docker run -d --expose 81 --expose 82 myImage
LINK: Link this container to other containers.
docker run -d --link herContainer --link theirContainer myImage
Run The App-
Overriding Image Defaults
33. MOUNT vs. VOLUME: Mount the [src] file/directory on host machine to [dst]
file/directory on container.
--mount type=bind,source=[src],target=[dst],[readonly]
-v [src]:[dst]
Difference in behavior?
While bind-mount a file or directory that does not yet exist on the host machine:
Using -v : It is always created as a directory.
Using âmount: Docker does not create it, but generates an error
Run The App-
Mount and Volume
34. $docker inspect myContainer
It will inspect the container!
The output is a json object which shows the configuration of the container
Inspect What You Ran
35. $docker inspect myContainer
It will inspect the container!
The output is a json object which shows the configuration of the container
Inspect What You Ran
36. $docker inspect myContainer
It will inspect the container!
The output is a json object which shows the configuration of the container
Inspect What You Ran
You may format the output using --format
Address the part you need in inspect json output.
And set the result to be in json format:
39. docker stop myContainer
docker start myContainer
docker restart myContainer
Annnnnd ⊠Manage yourContainer
But let me say
docker ps only shows running container.
Use docker ps -a to get all containers.
docker stop will send The main process inside
the container a SIGTERM, and after a grace
period, SIGKILL.
Use docker kill to send other signals.
40. $docker exec -it myContainer bash
It will execute âbashâ on âmyContainerâ.
-it means -i -t ï
-i keep the STDIN (interactive)
-t Allocate a pseudo Terminal (Ctrl+C will work!)
You may execute any application on the container instead of âbashâ and
also send arguments. As an example:
$docker exec -it myContainer mysql -uroot myDb
âDrink Meâ
41. $docker exec -it myContainer bash
It will execute âbashâ on âmyContainerâ.
-it means -i -t ï
-i keep the STDIN (interactive)
-t Allocate a pseudo Terminal (Ctrl+C will work!)
You may execute any application on the container instead of âbashâ and
also send arguments. As an example:
$docker exec -it myContainer mysql -uroot myDb
âDrink Meâ
âEat Meâ
Use Ctrl+P Ctrl+Q to go out of container
instead of exit.
42. Main Process, how are you?
docker logs [OPTIONS] myContainer
Show the logs of your main process on container.
OPTIONS:
--tail Number of lines to show (from the end) --tail 100
-t Show timestamp of each log entry (each line)
-f Follow the log
--since Show logs since a defined time --since 2013-01-02T13:23:37
--until Show logs until a defined time --until 42m
You may use a direct time or relative time for both since and until
43. p.b.u.h
docker rm 7ac899b82637
Remove the container with id of 7ac899b82637
You may use --force to force!
Tip of today: Use this command to remove all stopped containers.
$docker rm $(docker ps -a -q)
Tip of tomorrow: Use --link to remove a link between 2 containers.
$docker rm --link /webapp/redis
44. âŠand its image.
docker rmi myImage
Remove the image âmyImageâ.
You may use --force to force!
Try not to use this.
46. Pull
docker pull theirImage:v2
Pull âtheirImage:v2â from docker registry.
It will pull âlatestâ if you do not mention the tag.
You also may use digest to pull a specific build, not the last updated one.
docker pull ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2
Or use another registry than dockerhub:
docker pull myregistry.local:5000/testing/test-image
47. Commit
docker commit myContainer myImage:v2
Commit âmyContainerâ to a new image: âmyImageâ with tag âv2â
--change for running Dockerfile Commands before committing.
$ docker inspect -f "{{ .Config.Env }}" c3f279d17e0a
[HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]
$ docker commit --change "ENV DEBUG true" c3f279d17e0a svendowideit/testimage:version3
f5283438590d
$ docker inspect -f "{{ .Config.Env }}" f5283438590d
[HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DEBUG=true]
48. Push
docker push registry-host:5000/myImage
Push âregistry-host:5000/myImageâ to my local docker registry.
Use âtagâ before to tag your image in a right way:
docker tag myImage registry-host:5000/myImage