Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Docker
Saeed Hajizadeh
Index
• Pre-Concepts
• Concepts
• Warm Up
• Go To Shell
• Let’s Commit
PRE CONCEPTS
Literature
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)”
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.
Pre-Concepts
• DevOps Automation Tools Sample:
Infrastructure as code
Ansible, Terraform, Puppet, Chef
CI/CD
Jenkins, Shippable, Bamboo, Azure
DevOps
Test automation
Selenium, Cucumber, Apache Jmeter
ChatOps
Hubot, Lita, Cog
Orchestration
Kubernetes, Swarm, Mesos
Deployment
Elastic Beanstalk, Octopus, Vamp
Measurement
NewRelic, Kibana, Datadog,
DynaTrace
Containerization
Docker, Rocket, Unik
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.
CONCEPTS
Docker Literature
Concepts
• Containerization
– The use of Linux containers to deploy applications
• Flexible
• Lightweight
• Interchangeable
• Portable
• Scalable
• Stackable
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
Concepts
• Containers vs. VMs
Concepts
• Containers vs. VMs
Concepts
• Containers vs. VMs
Docker Architecture
Like Docker Hub
Docker Architecture(x2)
$sudo service docker restart
Restart the docker daemon
A Tree, Just Like a GIT Tree
A Tree, Just Like a GIT Tree
WARM UP
A quick start
Install Docker
Use This link to install Docker on Ubuntu :
https://docs.docker.com/install/linux/docker-ce/ubuntu/
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
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.
Start!
Check you Docker version and Info:
$ docker --version
Docker Version
$ docker info
A Brief of Containers and Images and other stats
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!
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!
GO TO SHELL
It’s time to
Docker Command Starter Pack
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]
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
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
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
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.
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
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
$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
$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
$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:
Docker Starter Pack
docker stop myContainer
docker start myContainer
docker restart myContainer
Annnnnd … Manage yourContainer
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.
$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”
$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.
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
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
…and its image.
docker rmi myImage
Remove the image “myImage”.
You may use --force to force!
Try not to use this.
LET’S COMMIT
You told me it’s like a got, so
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
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]
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
Decide On Base Image For Java

More Related Content

Docker Starter Pack

  • 2. Index • Pre-Concepts • Concepts • Warm Up • Go To Shell • Let’s Commit
  • 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.
  • 6. Pre-Concepts • DevOps Automation Tools Sample: Infrastructure as code Ansible, Terraform, Puppet, Chef CI/CD Jenkins, Shippable, Bamboo, Azure DevOps Test automation Selenium, Cucumber, Apache Jmeter ChatOps Hubot, Lita, Cog Orchestration Kubernetes, Swarm, Mesos Deployment Elastic Beanstalk, Octopus, Vamp Measurement NewRelic, Kibana, Datadog, DynaTrace Containerization Docker, Rocket, Unik
  • 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
  • 15. Docker Architecture(x2) $sudo service docker restart Restart the docker daemon
  • 16. A Tree, Just Like a GIT Tree
  • 17. A Tree, Just Like a GIT Tree
  • 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:
  • 38. docker stop myContainer docker start myContainer docker restart myContainer Annnnnd … Manage yourContainer
  • 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.
  • 45. LET’S COMMIT You told me it’s like a got, so
  • 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
  • 49. Decide On Base Image For Java