Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Introduction - Docker &
Docker Compose
Docker Ahmedabad Meetup
About Me
Ketan Parmar
● Education: Ph.D Computer Science (Grid Computing)
● Experience: 10 years
● Twitter: @kpbird
● LinkedIn: https://www.linkedin.com/in/kpbird/
● Books Review:
○ Mastering AWS Development
○ Developing RESTful Web Services with Jersey 2.0
History
1. Session Based Computing
2. Non-Session Based Computing (eg. VDI or VM)
3. Containers
Why Containers?
1. Simplifying Configuration
2. Code Pipeline Management
3. Developer Productivity
4. App Isolation
5. Server Consolidation
6. Debugging Capabilities
7. And more..
VM vs Containers
Deploy
TERMINOLOGY
1. Docker client: command line that can be installed on Mac OS X or Windows to control most of the Docker
workflow and talk to Docker servers
2. Docker server: Docker running in daemon mode on a Linux server. The servers starts, runs, and stops/destroys
containers.
3. Docker images: layered filesystems described via metadata that represent all the dependencies necessary to
run an application.
4. Docker repository: the library of available Docker images, can be public (Docker Hub) or private
5. Docker container: a single instance of a Linux container built from the Docker image. There can be many
containers built from a single Docker image.
6. Docker host: the underlying Linux operating system that hosts the Docker daemon
7. Docker Hub: public repository of Docker images
8. Docker Trusted Registry: private image repository
9. Docker Toolbox: specialized installer for Docker tools on Mac and Windows
10. Docker Machine: automated Docker provisioning
11. Docker Swarm: host clustering and container scheduling
12. Docker Compose: define multi-container applications
13. Docker Registry: open source Docker image distribution
14. Docker Engine: creates and runs Docker containers
Docker Commands
● Attach Attach local standard input, output, and error streams to a running container
● Build Build an image from a Dockerfile
● Create Create a new container
● Deploy Deploy a new stack or update an existing stack
● Images List images
● Info Display system-wide information
● Kill Kill one or more running containers
● Load Load an image from a tar archive or STDIN
● Login Log in to a Docker registry
● Logout Log out from a Docker registry
● Logs Fetch the logs of a container
● Pause Pause all processes within one or more containers
● Port List port mappings or a specific mapping for the container
● Ps List containers
● Pull Pull an image or a repository from a registry
● Push Push an image or a repository to a registry
Docker Commands
● Rename Rename a container
● Restart Restart one or more containers
● Rm Remove one or more containers
● Rmi Remove one or more images
● Run Run a command in a new container
● Search Search the Docker Hub for images
● Start Start one or more stopped containers
● Stats Display a live stream of container(s) resource usage statistics
● Stop Stop one or more running containers
● Tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
● Top Display the running processes of a container
● Unpause Unpause all processes within one or more containers
● Update Update configuration of one or more containers
● Version Show the Docker version information
● Wait Block until one or more containers stop, then print their exit codes
Pull & Run Container
● docker pull nginx
● docker images
● docker run --name nginx -d -p 8080:80 nginx
● docker ps
● docker stop nginx
Build Docker Image
FROM ubuntu
MAINTAINER Ketan Parmar (ketanbparmar@yahoo.com)
RUN apt-get update
RUN apt-get install -y nginx
ENTRYPOINT [“/usr/sbin/nginx”,”-g”,”daemon off;”]
EXPOSE 80
● docker build -t mynginx:latest .
● docker images
● docker run --name mynginx -d -p 8080:80 nginx
Docker file commands
● ADD Copies a file from the host system onto the container
● CMD The command that runs when the container starts
● ENTRYPOINT
● ENV Sets an environment variable in the new container
● EXPOSE Opens a port for linked containers
● FROM The base image to use in the build. This is mandatory and must be the first command in the
file.
● MAINTAINER An optional value for the maintainer of the script
● ONBUILD A command that is triggered when the image in the Dcokerfile is used as a base for another
image
● RUN Executes a command and save the result as a new layer
● USER Sets the default user within the container
● VOLUME Creates a shared volume that can be shared among containers or by the host machine
● WORKDIR Set the default working directory for the container
Docker Compose
The answer to these questions is Docker
Compose, “a tool for defining and running
complex applications with Docker. With
Compose, you define a multi-container
application in a single file, then spin your
application up in a single command which does
everything that needs to be done to get it
running.”
Example
1 Redis container
3 Node containers
1 Nginx container
version: "3.3"
services:
nginx:
build: ./nginx
links:
- node1:node1
- node2:node2
- node3:node3
ports:
- "80:80"
node1:
build: ./node
links:
- redis
ports:
- "8080"
Docker Compose (docker-compose.yml)
node2:
build: ./node
links:
- redis
ports:
- "8080"
node3:
build: ./node
links:
- redis
ports:
- "8080"
redis:
image: redis
ports:
- "6379"
Top-level keys that define a section in the configuration file such as build, deploy, depends_on, networks, and so on, are
listed with the options that support them as sub-topics. This maps to the <key>: <option>: <value> indent structure of the
Compose file.
Services
Build
Command
Volumes
Ports
Networks
Dockerfile
ARG
Docker Compose (docker-compose.yml)
Build Build or rebuild services
Config Validate and view the Compose file
Create Create services
Down Stop and remove containers, networks, images, and volumes
Events Receive real time events from containers
Exec Execute a command in a running container
Help Get help on a command
Images List images
Kill Kill containers
Logs View output from containers
Pause Pause services
Port Print the public port for a port binding
Ps List containers
Pull Pull service images
Push Push service images
Restart Restart services
Rm Remove stopped containers
Run Run a one-off command
Scale Set number of containers for a service
Start Start services
Stop Stop services
Top Display the running processes
Unpause Unpause services
Up Create and start containers
Docker Compose CLI
Thank You

More Related Content

Introduction of Docker and Docker Compose

  • 1. Introduction - Docker & Docker Compose Docker Ahmedabad Meetup
  • 2. About Me Ketan Parmar ● Education: Ph.D Computer Science (Grid Computing) ● Experience: 10 years ● Twitter: @kpbird ● LinkedIn: https://www.linkedin.com/in/kpbird/ ● Books Review: ○ Mastering AWS Development ○ Developing RESTful Web Services with Jersey 2.0
  • 3. History 1. Session Based Computing 2. Non-Session Based Computing (eg. VDI or VM) 3. Containers
  • 4. Why Containers? 1. Simplifying Configuration 2. Code Pipeline Management 3. Developer Productivity 4. App Isolation 5. Server Consolidation 6. Debugging Capabilities 7. And more..
  • 7. TERMINOLOGY 1. Docker client: command line that can be installed on Mac OS X or Windows to control most of the Docker workflow and talk to Docker servers 2. Docker server: Docker running in daemon mode on a Linux server. The servers starts, runs, and stops/destroys containers. 3. Docker images: layered filesystems described via metadata that represent all the dependencies necessary to run an application. 4. Docker repository: the library of available Docker images, can be public (Docker Hub) or private 5. Docker container: a single instance of a Linux container built from the Docker image. There can be many containers built from a single Docker image. 6. Docker host: the underlying Linux operating system that hosts the Docker daemon 7. Docker Hub: public repository of Docker images 8. Docker Trusted Registry: private image repository 9. Docker Toolbox: specialized installer for Docker tools on Mac and Windows 10. Docker Machine: automated Docker provisioning 11. Docker Swarm: host clustering and container scheduling 12. Docker Compose: define multi-container applications 13. Docker Registry: open source Docker image distribution 14. Docker Engine: creates and runs Docker containers
  • 8. Docker Commands ● Attach Attach local standard input, output, and error streams to a running container ● Build Build an image from a Dockerfile ● Create Create a new container ● Deploy Deploy a new stack or update an existing stack ● Images List images ● Info Display system-wide information ● Kill Kill one or more running containers ● Load Load an image from a tar archive or STDIN ● Login Log in to a Docker registry ● Logout Log out from a Docker registry ● Logs Fetch the logs of a container ● Pause Pause all processes within one or more containers ● Port List port mappings or a specific mapping for the container ● Ps List containers ● Pull Pull an image or a repository from a registry ● Push Push an image or a repository to a registry
  • 9. Docker Commands ● Rename Rename a container ● Restart Restart one or more containers ● Rm Remove one or more containers ● Rmi Remove one or more images ● Run Run a command in a new container ● Search Search the Docker Hub for images ● Start Start one or more stopped containers ● Stats Display a live stream of container(s) resource usage statistics ● Stop Stop one or more running containers ● Tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE ● Top Display the running processes of a container ● Unpause Unpause all processes within one or more containers ● Update Update configuration of one or more containers ● Version Show the Docker version information ● Wait Block until one or more containers stop, then print their exit codes
  • 10. Pull & Run Container ● docker pull nginx ● docker images ● docker run --name nginx -d -p 8080:80 nginx ● docker ps ● docker stop nginx
  • 11. Build Docker Image FROM ubuntu MAINTAINER Ketan Parmar (ketanbparmar@yahoo.com) RUN apt-get update RUN apt-get install -y nginx ENTRYPOINT [“/usr/sbin/nginx”,”-g”,”daemon off;”] EXPOSE 80 ● docker build -t mynginx:latest . ● docker images ● docker run --name mynginx -d -p 8080:80 nginx
  • 12. Docker file commands ● ADD Copies a file from the host system onto the container ● CMD The command that runs when the container starts ● ENTRYPOINT ● ENV Sets an environment variable in the new container ● EXPOSE Opens a port for linked containers ● FROM The base image to use in the build. This is mandatory and must be the first command in the file. ● MAINTAINER An optional value for the maintainer of the script ● ONBUILD A command that is triggered when the image in the Dcokerfile is used as a base for another image ● RUN Executes a command and save the result as a new layer ● USER Sets the default user within the container ● VOLUME Creates a shared volume that can be shared among containers or by the host machine ● WORKDIR Set the default working directory for the container
  • 13. Docker Compose The answer to these questions is Docker Compose, “a tool for defining and running complex applications with Docker. With Compose, you define a multi-container application in a single file, then spin your application up in a single command which does everything that needs to be done to get it running.” Example 1 Redis container 3 Node containers 1 Nginx container
  • 14. version: "3.3" services: nginx: build: ./nginx links: - node1:node1 - node2:node2 - node3:node3 ports: - "80:80" node1: build: ./node links: - redis ports: - "8080" Docker Compose (docker-compose.yml) node2: build: ./node links: - redis ports: - "8080" node3: build: ./node links: - redis ports: - "8080" redis: image: redis ports: - "6379"
  • 15. Top-level keys that define a section in the configuration file such as build, deploy, depends_on, networks, and so on, are listed with the options that support them as sub-topics. This maps to the <key>: <option>: <value> indent structure of the Compose file. Services Build Command Volumes Ports Networks Dockerfile ARG Docker Compose (docker-compose.yml)
  • 16. Build Build or rebuild services Config Validate and view the Compose file Create Create services Down Stop and remove containers, networks, images, and volumes Events Receive real time events from containers Exec Execute a command in a running container Help Get help on a command Images List images Kill Kill containers Logs View output from containers Pause Pause services Port Print the public port for a port binding Ps List containers Pull Pull service images Push Push service images Restart Restart services Rm Remove stopped containers Run Run a one-off command Scale Set number of containers for a service Start Start services Stop Stop services Top Display the running processes Unpause Unpause services Up Create and start containers Docker Compose CLI