Giter Site home page Giter Site logo

learning_docker's Introduction

Learning_Docker

A container is a software code package containing an application's code, its libraries, and other dependencies. Containerization makes your applications portable so that the same code can run on any device. A virtual machine is a digital copy of a physical machine.

An "image" is a lightweight, standalone, and executable package that contains everything needed to run a piece of software, including the code, runtime, system tools, libraries, and system dependencies.

Choose base image wisely! never use LATEST in base image in dockerfile as since latest may vary in time, does can you enviroment become incompatible. So be specific in base images.

Dockerfile

It contains a set of instructions and commands that specify how to create a Docker image, what should be included in the image, and how the image should be configured.

exclude file in .dockerignore

by Defualt docker container gives us root access but this open more security vulnerablities. Hence always add a user access to containers.

Difference between RUN and CMD intstruction in dockerfile' RUN: commands are executed when images is being built CMD: command is executed when container is getting started

Dockerfile can have multiple RUN instruction but logically only one CMD instruction.

Speeding up builds

Docker images are build up in layers and each instruction in dockerfile can be considered a layer. Docker reuses the layer if there is no change in that layer/instruction/files. Once a layer is rebuil, all the following layers have to rebuilt. So write instruction in such a way that unecessary building of layers in not happening One such example is npm install, you do don't want to install node modules always when you modify application. if any changes happens at upper layers of npm install, npm install get executed as well. :( So write instructions in such a way that stable instructions are at top, volatile instructions are at bottom.

Pruning

Docker image pruning is a process that removes unused, dangling, or unnecessary images from your local Docker environment to free up disk space. Over time, as you work with Docker containers and images, you can accumulate a significant amount of data that may no longer be needed. Pruning helps to keep your system clean and prevent it from running out of storage space.

first prune containers and then prune images and some containers can use come dangling images so those images might not be pruned.

Sharing images

you can share images in hub.docker.com

when you push an images all the layers contained with the image are push, however if you push a modified image, only those modified layers and following layers are pushed, makeing the push process faster.

Port Mapping

Host machine and container are isolated, so inorder to use the service of container, port mapping is done. It involves mapping a port on the host machine to a port within the container, allowing external or other containers to communicate with services running inside the container through the host's IP address and a specific port number.

The EXPOSE instruction in a Dockerfile is used to document the network ports that a container listens on. It doesn't actually publish or open any ports; it's a metadata declaration that provides information to users about which ports are intended to be used for network communication with the container.

Persisting data in container

Data in conatainer are volatile meaning once the container is deleted, the container data is lost. Hence comes volume to the rescue, In Docker, a volume is a mechanism for persisting data outside of the container's filesystem. Volumes provide a way to store and share data between containers and the host machine, and they are a key feature for managing data in containerized applications.

learning_docker's People

Contributors

laxmanbalaraman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.