Git Product home page Git Product logo

docker-101's Introduction

What is Containerization?

Containerization is the packaging together of software code with all it’s necessary components like libraries, frameworks, and other dependencies so that they are isolated in their own "container."

Read More

Docker-101

What is Docker?

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications.

Read More

VM vs Container

VM Container
Use Hypervisors to virtualy emulate physical hardware. Use the OS Kernal to access underlying host hardware.
Slow start up, as the VM OS needs to be launched first Quick start up, as containers only need to access the OS Kernal.
Difficult depenceny managed for applications to be deployed. Easy dependeny management, as containers natively isolate and load all the dependencies into the internal File system.
Require high effort to backup and restore applications, as all the dependencies go on single File system. Applications can be easily migrated between machines and environments, as each container can be represented as 1 Docker file.

Key Concepts

  1. Dockerfile: This is a text document, that contains all the commands required to assemble the Image of the application. Docker can automatically build images by reading instructions within the Dockerfile document.

    Read More

  2. Image: A Docker image is a file used to execute code in a Docker container. Docker images act as a set of instructions to build a Docker container, like a template.

    Read More

  3. Container: A container is an instance of an image, with all the dependencies and runtime managed required to run the application. This also has access to Host OS Kernal to access the underlying physical hardware.

    Read More

  4. Registry: A registry is a storage and content delivery system, holding named Docker images, available in different tagged versions. Images are also refered as Repositories.

    Read More

Docker Architecture

Drawing

Working Session:

How to Dockerize an Application

Steps:

  1. Create a new docker definition file in the root directory of your application and name the file as ##### Dockerfile
  2. Add following commands to the Dockerfile:

For JavaScript/Node Application

FROM node:alpine
COPY . /app
WORKDIR /app
CMD node <JS_FILE_NAME>

For ASP.Net Core Application

 FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
 WORKDIR /app
 EXPOSE 80
 FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
 WORKDIR /src
 COPY ["<PROJECT_NAME>.csproj", ""]
 RUN dotnet restore "./<PROJECT_NAME>.csproj"
 COPY . .
 WORKDIR "/src/."
 RUN dotnet build "<PROJECT_NAME>.csproj" -c Release -o /app/build
 FROM build AS publish
 RUN dotnet publish "<PROJECT_NAME>.csproj" -c Release -o /app/publish
 FROM base AS final
 WORKDIR /app
 COPY --from=publish /app/publish .
 ENTRYPOINT ["dotnet", "<PROJECT_NAME>.dll"]
  1. Open a Command Prompt/PowerShell/Terminal at the root directory of the application to be Containerized.
  2. Build the Docker Image for the application using Docker Build Command, as below:
docker build -t <IMAGE_NAME> .

Wait for build to finish. 5. Run the Docker image, using the Docker Run command.

docker run <IMAGE_NAME>
  1. To push Docker image to Docker Hub, use Docker Login command to login to the Registry.
docker login
  1. Assign a Tag to Docker Image before pushing, using the Docker Tag command as below:
docker tag <IMAGE_NAME> <DOCKER_HUB_USERNAME:IMAGE_NAME>
  1. Push Docker Image, to Docker Hub using the Push command as follows:
docker push <DOCKER_HUB_USERNAME:IMAGE_NAME>

Wait for push activity to be successful.

NOTE: The pushed Docker Image, can now be pulled on any host machine running Docker Daemon using the Docker Pull Command and then can be ran easily as below:

docker pull <DOCKER_HUB_USERNAME:IMAGE_NAME>
docker run -d -p 8080:80 <DOCKER_HUB_USERNAME:IMAGE_NAME>

docker-101's People

Contributors

harigovind511 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.