Skip to main content

Dcoker 2nd article

  

Introduction to Docker

Docker is an open-source platform that automates the deployment of applications inside software containers. This ensures that the software behaves the same way, regardless of where it is deployed. Docker achieves this by combining a lightweight container runtime with workflows and tooling that help manage and deploy applications.

Core Concepts of Docker

1. Docker Images A Docker image is a lightweight, standalone, executable package that includes everything needed to run a piece of software, including the code, runtime, libraries, environment variables, and config files.

Example Command: To pull an existing image from Docker Hub:

bas
docker pull ubuntu

2. Docker Containers A container is a runtime instance of an image—what the image becomes in memory when executed.

Example Command: To run a container from the ubuntu image:

bas
docker run -it ubuntu

3. Dockerfile A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.

Example Command: Creating a simple Dockerfile:

Dockerfile
FROM ubuntu RUN apt-get update && apt-get install -y nginx CMD ["nginx", "-g", "daemon off;"]

4. Docker Compose Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services.

Example Command: To start up a project using docker-compose:

bas
docker-compose up

5. Docker Hub Docker Hub is a service provided by Docker for finding and sharing container images with your team. It is a public registry that contains a large number of images available for use.

Example Command: To login to Docker Hub:

bash
docker login

Common Docker Commands and Their Usage

CommandDescriptionExample Usage
docker pullPulls an image from a registrydocker pull ubuntu
docker buildBuilds an image from a Dockerfiledocker build -t myimage .
docker runRuns a command in a new containerdocker run -it ubuntu bash
docker pushPushes an image to a registrydocker push myimage
docker execRuns a command in a running containerdocker exec -it mycontainer bash
docker stopStops one or more running containersdocker stop mycontainer
docker startStarts one or more stopped containersdocker start mycontainer
docker rmRemoves one or more containersdocker rm mycontainer
docker rmiRemoves one or more imagesdocker rmi myimage
docker logsFetches logs of a containerdocker logs mycontainer
docker inspectReturns low-level information on Docker objectsdocker inspect mycontainer
docker network createCreates a new networkdocker network create mynetwork
docker volume createCreates a volume for persistent data storagedocker volume create myvolume
docker compose upBuilds, (re)creates, starts, and attaches to containersdocker-compose up
docker compose downStops containers and removes containers, networks, volumesdocker-compose down

Comments

Popular posts from this blog

DevOps Vs DevSecOps

   DevOps and DevSecOps are two methodologies that have gained traction in the IT industry for streamlining software development and deployment. However, their approach to security and operations differs, making each suitable for different types of projects and organizational needs. Let's explore DevOps versus DevSecOps with a real-time example, focusing on their distinctions, integration, and practical applications. DevOps: The Foundation DevOps is a cultural and professional movement that emphasizes collaboration and communication between software developers and other IT professionals while automating the process of software delivery and infrastructure changes. It aims to shorten the development life cycle and provide continuous delivery with high software quality. Core Principles: Continuous Integration and Continuous Deployment (CI/CD): Automate building, testing, and deployment of applications. Collaboration: Breaking down silos between teams (developers, IT operations...

Deploying a Node.js project to Azure App Services using Azure DevOps pipelines

Deploying a Node.js project to Azure App Services using Azure DevOps pipelines is a robust way to automate deployment processes and integrate continuous integration and deployment (CI/CD) practices into your workflow. This guide will walk you through the setup of an Azure DevOps pipeline to deploy a Node.js application from GitHub or Azure Repos to Azure App Services. Prerequisites Before you begin, ensure you have the following: An Azure account. You can sign up for a free account here . A GitHub or Azure Repos account with your Node.js project. An Azure DevOps account. Create one here if you don't have it. Step 1: Prepare Your Node.js Application Make sure your Node.js application is ready and includes a package.json file in the root. This file is crucial as it contains dependency information and scripts needed for your application. Step 2: Create an Azure Web App Log into Azure Portal: Visit https://portal.azure.com . Create a Web App: Click on "Create a resource". ...

Git Cheat Sheet

  Git Cheat Sheet Category Command Description Setup git config --global user.name "[name]" Set a name that will be attached to your commits and tags. git config --global user.email "[email]" Set an email that will be attached to your commits and tags. git init Initialize a new git repository in the current directory. git clone [url] Clone a repository into a new directory. Stage & Snapshot git status Show modified files in the working directory, staged for your next commit. git add [file] Add a file as it looks now to your next commit (stage). git reset [file] Unstage a file while retaining the changes in the working directory. git diff Show diff of what is changed but not staged. git diff --staged Diff of what is staged but not yet committed. git commit -m "[message]" Commit your staged content as a new commit snapshot. Branch & Merge git branch List all of the branches in your repo. git branch [name] Create a new branch at the current commit. gi...