2. Docker
• containerization platform which packages an application and its all
dependencies together into a container so as to ensure that application works
seamlessly in any environment i.e development, production or test.
• it started with dotcloud as a platform as a service like heroku.
• docker written in:-
it's not c++
it's not python
it's not ruby
it's not java
3. Containerization v/s Virtualization
• Virtualization:-
• technique of importing a guest os on top of host os
• brings abstraction to the hardware
• multiple os in same machine
• multiple VMS in same os leads to performance degradation
• Containerization:-
• kind of virtualization using host os
• brings abstraction to the software
• multiple containers runs efficiently
5. why does this matter?
• Tagline - build, ship, run, any app, anywhere
• Build: package your application in a container
• Ship: move that cotainer from one machine to other machine
• Run: execute that container(i.e your application)
• Any App: anything that runs on linux
• Anywhere: physical machine, local vm,cloud instance..
• Execution is fast and light weight(container starts in miliseconds )
• Hence It's reliable and consistent for deployment
7. Docker Engine
Docker Engine is a client-server
application with these major
components:
• A server which is a type of long-
running program called a daemon
process (the dockerd command).
• A REST API which specifies interfaces
that programs can use to talk to the
daemon and instruct it what to do.
• A command line interface (CLI) client
(the docker command)
9. Docker Objects
IMAGES
• An image is a read-only template with instructions for creating a Docker container. Often,
an image is based on another image, with some additional customization. For example, you
may build an image which is based on the ubuntu image, but installs the Apache web server
and your application, as well as the configuration details needed to make your application
run.
• To build your own image, you create a Dockerfile with a simple syntax for defining the steps
needed to create the image and run it. Each instruction in a Dockerfile creates a layer in the
image. When you change the Dockerfile and rebuild the image, only those layers which have
changed are rebuilt. This is part of what makes images so lightweight, small, and fast, when
compared to other virtualization technologies.
10. Docker Objects
CONTAINERS
• A container is a runnable instance of an image. You can create, start, stop, move, or delete a
container using the Docker API or CLI. You can connect a container to one or more
networks, attach storage to it, or even create a new image based on its current state.
• By default, a container is relatively well isolated from other containers and its host machine.
You can control how isolated a container’s network, storage, or other underlying subsystems
are from other containers or from the host machine.
• A container is defined by its image as well as any configuration options you provide to it
when you create or start it. When a container is removed, any changes to its state that are
not stored in persistent storage disappear.
15. • bash:~$ docker pull <imageName:tag> #pull image from docker hub
• bash:~$ docker run [options] <imageName:tag/Id> [commands] #create container
• bash:~$ docker images #list all Images in host machine
• bash:~$ docker ps #list all running containers
• bash:~$ docker ps -a #list all created containers
• bash:~$ docker inspect <imageId/containerId> #show low-level Information
• bash:~$ docker history <imageName:tag/Id> #history related to Image
• bash:~$ docker [stop/start/pause/unpause/attach] <containerId> #switch container states
• bash:~$ docker top <containerId> #show top process in container
• bash:~$ docker [rm/rmi] [containerId/imageId] #remove container/image
• bash:~$ docker exec [options] <containerId> [command] #Exec in running container
Useful Commands
16. Dockerfile
• Format Of Dockerfile
FROM ubuntu #use ubuntu base image
RUN apt-get update && apt-get install -y curl && apt-get install -y sudo
RUN curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
RUN apt-get install -y nodejs
ADD ./ /smallTalk #add current directory files to /smallTalk folder in createdImage
WORKDIR /smallTalk #present working directory set as /smallTalk
ENTRYPOINT #pass entry commands
• lets run smallTalk application in docker container
• docker run -it -p 3001:3001 --name smallTalk small_talk npm start
• docker run -it -p 3001:3001 --name smallTalkRedis --link
redisContainer:redisContainer small_talk npm start
17. Docker Tools
• Docker machine
Docker machine lets you spin up docker host VMs locally on your laptop, a cloud-provider
(AWS, Azure etc) and your private data center (OpenStack, Vsphere etc).
• Docker swarm
Used to manage a group of docker engines as a single entity and provide orchestration
• Docker compose
Docker Compose has a simple way of describing an application as several containers that
work together, how they should be linked, and what ports should be exposed to the end
user. The Docker container environments are defined in a “docker-compose.yml” file