Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Docker @ Atlogys

57 views

Published on

Tech Talk on Docker - Docker is a computer program that performs OS virtualization, also known as containerization.
Written in: Go
Supported OS: Linux, Windows, macOS

This technology is widely used within Atlogys as a best practice during development.

Hear out senior engineer Mr. Ram Awadh deliver this information session which also includes a demo.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Docker @ Atlogys

  1. 1. Introduction To Docker Build and Ship Application with Docker By - Ram Awadh Chauhan Senior Software Engineer Atlogys Technical Consulting
  2. 2. Today’s Agenda 1: About docker 2: Difference between Virtualization and Containerization. 3: Why Docker? 4: Docker Architecture, basic terms and commands 5: Dockerizing a project with docker (Django App, live Demo, Volume mount Etc) ● Environment variables (ADD, COPY, ENV, EXPOSE, FROM, WORKDIR, ENTRYPOINT, CMD) https://docs.docker.com/engine/reference/builder/#environment-replacement ● Differences b/w CMD and ENTRYPOINT with example ● Create a DockerFile ● Build an Image ● Run the Application ● Volume mount from Host machine to container ● Start, Stop , Delete, Remove commands 7: Who are using it? 8: Q & A sessions.
  3. 3. About Docker 1: Docker is a computer program that performs operating-system-level virtualization also known as containerization. 2: Docker firstly started by “Solomon Hykes” in france as internal Project inside dotCloud. 3: It was first released in March 2013 as open source Project. 4: Docker is written in GO language. 5: It was primarily supported only Linux operating system where it used the resource isolation feature of linux kernel. 6: Docker is used to run software packages called "containers". 7: In a typical example use case, one container runs a web server and web application, while a second container runs a database server that is used by the web application. 8: Containers are isolated from each others and use their own set of tools and libraries. 9: Containers can communicate through well-defined channels. 10: All containers use the same kernel and are therefore more lightweight than virtual machines.
  4. 4. Difference between Virtualization and Containerization Virtualization Containerization
  5. 5. Why Docker? 1: Light weight: Docker container are light weight, only include binaries of the application. 2: Efficient: Minimizes deployment cost and it is very efficient. 3: Fixes Environment based Issue: Removes the environment based issues, like code is working on some environment and not working on some other environments. 4: Very Flexible: Can be ported on any environment by pulling. Copying from one environment to another environment even can be run inside Amazon EC2 and Google Compute Engine instance also on VMS. 5: Isolation: Docker makes sure each container has its own resources that are isolated from other containers.
  6. 6. Docker Architecture, Basic Terms and Commands
  7. 7. Docker Architecture, Basic Terms and Commands …. Continued Docker Client: This (docker Client) is the primary way by which docker user interact with docker i.e. docker run Docker Registries: Docker registry stores docker images. Docker hub and Docker Cloud are public registries that anyone can use, and Docker is configured to look for images on Docker hub by default. Docker pull <image-name> can be used to pull the images. And Docker push <mage=name > to publish docker images on docker hub. Docker Images: An Image is a read-only template with instructions for creating a Docker container. Docker Container: A Container is a runnable instance of an Image. These can be created, started, stopped or deleted using docker Api or CLI commands.
  8. 8. Docker Architecture, Basic Terms and Commands …. Continued List of important commands which can be used by Docker CLI: 1. docker pull: Pull a image from registry 2. Docker build : build and image from dockerfile 3. Docker run: Runs a container 4. docker start: Start one or more stoped container 5. docker stop: Stop one or more running containers 6. docker ps: List containers which are running 7. docker ps -a: List all containers 8. docker kill: Kill one or more running containers 9. docker logs: Fetch the logs of a container 10. docker login: Login into Docker registry like Docker hub 11. docker logout: Logout from the Docker registry
  9. 9. Docker Architecture, Basic Terms and Commands …. Continued 12: docker rename: Rename a container 13: docker restart: Restart one or more containers 14: docker rm : Remove one or more containers 15: docker rmi: Remove one or more images 16: docker stats: Display a live stream of container(s) resource usage statistics 17: docker tag: Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE 18: docker top: Display the running processes of a container 19: docker version: Show the docker version 16: docker port: List port mappings or a specific mapping for the container 15: Docker history: Shows the history of an image 16: docker push: Push a image into the registry
  10. 10. Docker Architecture, Basic Terms and Commands …. Continued 17: Docker export: Export a container’s filesystem as a tar archive 18: Docker image <subcommand> : Manage images with following commands ● docker image import: Import the contents from a tarball to create a filesystem image ● docker image inspect: Display detailed information on one or more images ● docker image load: Load an image from a tar archive or STDIN ● docker image ls: List images ● docker image prune: Remove unused images ● docker image pull: Pull an image or a repository from a registry ● docker image push: Push an image or a repository to a registry ● docker image rm: Remove one or more images
  11. 11. About Dockerfile and commands The Dockerfile is a building block of instruction to build the image, also Dockerfile is a script, composed of various commands (instructions) and arguments listed successively to automatically perform actions on a base image in order to create (or form) a new one. They are used for organizing things and greatly help with deployments by simplifying the process start-to-finish. Commands: ADD, CMD, ENTRYPOINT, ENV, EXPOSE, FROM, MAINTAINER, RUN, USER, VOLUME, WORKDIR
  12. 12. About Dockerfile and commands ADD: The ADD command gets two arguments: a source and a destination. It basically copies the files from the source on the host into the container's own filesystem at the set destination. If, however, the source is a URL (e.g. http://github.com/user/file/), then the contents of the URL are downloaded and placed at the destination. Example: docker ADD [source directory or URL] [destination directory]
  13. 13. About Dockerfile and commands CMD: The command CMD, similarly to RUN, can be used for executing a specific command. However, unlike RUN it is not executed during build, but when a container is instantiated using the image being built. Therefore, it should be considered as an initial, default command that gets executed (i.e. run) with the creation of containers based on the image. Example: CMD "echo" "Hello docker!"
  14. 14. About Dockerfile and commands ENTRYPOINT: ENTRYPOINT argument sets the concrete default application that is used every time a container is created using the image. For example, if you have installed a specific application inside an image and you will use this image to only run that application, you can state it with ENTRYPOINT and whenever a container is created from that image, your application will be the target.. Example: ENTRYPOINT application "argument", "argument", .. CMD "Hello docker!" ENTRYPOINT "echo"
  15. 15. About Dockerfile and commands ENV: The ENV command is used to set the environment variables (one or more). These variables consist of “key value” pairs which can be accessed within the container by scripts and applications alike. This functionality of Docker offers an enormous amount of flexibility for running programs. Example: ENV SERVER_WORKS 4
  16. 16. About Dockerfile and commands EXPOSE: The EXPOSE command is used to associate a specified port to enable networking between the running process inside the container and the outside world (i.e. the host). Example: EXPOSE 8080
  17. 17. About Dockerfile and commands FROM: It defines the base image to use to start the build process. It can be any image, including the ones you have created previously. If a FROM image is not found on the host, Docker will try to find it (and download) from the Docker Hub or other container repository. It needs to be the first command declared inside a Dockerfile. Example: FROM ubuntu:16.04
  18. 18. About Dockerfile and commands MAINTAINER: One of the commands that can be set anywhere in the file - although it would be better if it was declared on top - is MAINTAINER. This non-executing command declares the author, hence setting the author field of the images. It should come nonetheless after FROM. Example: MAINTAINER authors_name
  19. 19. About Dockerfile and commands RUN: The RUN command is the central executing directive for Dockerfiles. It takes a command as its argument and runs it to form the image. Unlike CMD, it actually is used to build the image (forming another layer on top of the previous one which is committed). Example: RUN pip install -r requirements.txt
  20. 20. About Dockerfile and commands USER: The USER directive is used to set the UID (or username) which is to run the container based on the image being built. Example: USER 751 VOLUME: The VOLUME command is used to enable access from your container to a directory on the host machine (i.e. mounting it). Example: VOLUME ["/my_files"]
  21. 21. About Dockerfile and commands WORKDIR: The WORKDIR directive is used to set where the command defined with CMD is to be executed. Example: WORKDIR ~/
  22. 22. Difference b/w CMD and ENTRYPOINT 1: You need at least one (ENTRYPOINT or CMD) defined (in order to run) 2: if just one is defined at runtime, CMD and ENTRYPOINT have the same effect 3: For both CMD and ENTRYPOINT, there are "shell" and "exec" versions 4: CMD arguments append to end of ENTRYPOINT sometimes a: If you use "shell" format for ENTRYPOINT, CMD is ignored. b: If you use "exec" format for ENTRYPOINT, CMD arguments are appended after. 5: ENTRYPOINT and CMD can be overridden via command line flags.
  23. 23. Sample Dockerfile FROM ubuntu:16.04 RUN apt-get update && apt-get -y upgrade RUN apt install -y libffi-dev python-docutils pkg-config python3-dev python3-pip RUN rm -r /usr/bin/python RUN ln -s /usr/bin/python3.5 /usr/bin/python RUN apt-get install -y python3-dev pkg-config RUN mkdir /home/docker-demo #RUN mkdir /var/code ADD . /home/docker-demo/ WORKDIR /home/docker-demo RUN pip3 install -r requirements.txt #RUN ln -s /home/docker-demo /var/code EXPOSE 8000 ENTRYPOINT ["python", "manage.py"] CMD ["runserver", "0.0.0.0:8000"]
  24. 24. Build docker file and run docker file Commands: docker build --rm -t docker-test . Run the images: docker run -d -v /home/ram/Work/PeopleTicker/docker-demo/first_app/templates/first_app:/home/dec ker-demo/first_app/templates/first_app -p 8000:8000 --name=demo docker-test
  25. 25. Push an image to dockerhub Prerequisites: You need to create an account and a repository in hub.docker.com Then need to follow below steps. -> docker login --username=<user-name> -> docker tag <image-name> <registry-name> -> docker push <repository-name>
  26. 26. Thank You !!!!

×