DevOps

Docker file

Dockerfile Dockerfile is basically a text file. It contains the set of instructions means how’s the container going to build according to user requirements. Dockerfile contains the configuration of container like Image type, Image Name, set of command, Ports and Networks. Docker Components Dockerfile contains docker components which includes Image type, Container name, docker Swarm, container Ports, Command instructions, Working directory Environment variables, author name etc… Docker Components types FROM :- for base image, this command must be on top of the dockerfile. RUN:- To execute commands, it will create a layer in image. MAINTAINER:- Author or Owner name COPY:- To copy files from local system to inside container. ADD:- Similar to copy, but it provide a feature to download files from internet. EXPOSE:- To expose the ports in docker container. WORKDIR:- To set working directory for a container CMD:- Execute commands but during container creation. ENTRYPOINTS:- Similar to CMD, but has higher prority over CMD. ENV:- Environment variables Lets Create ubuntu container using dockerfile and its components and deploy it Step:- 1. Create a file and using this name Dockerfile $ sudo nano Dockerfile FROM ubuntuWORKDIR /tmpRUN echo “Redient Security” > /tmp/testfile paste this above lines in Dockerfile Press Ctrl + x and press ‘Y’ to save it Now create Image using this Dockerfile $ sudo docker build -t test . here test is image name and Dot is for current working directory Run the below command $ sudo docker images Now create container from the test image which we have created using Dockerfile $ sudo docker run -it –name mycontainer test /bin/bash here mycontainer is container name and /bin/bash is for terminal After running above command, now you are in container and in /tmp directoryNow run the below commands to print the output of a file # ls# cat testfile Now you can see, we written the “Welcome to Redient Security” content in Dockerfile and we successfully save the in testfile and printed. Let’s take another example of Dockerfie, this time we will create one image and in that image or container we create one user and install ssh server expose port 22 for ssh. Open terminal and create one Dockerfile $ sudo nano Dockerfile Copy and paste the below lines in Dockerfile FROM ubuntu:18.04LABEL name=”Pramod Singh”LABEL email=”[email protected]”ENV NAME pramodENV PASS password123RUN mkdir -p /var/run/sshdRUN apt-get update && apt-get install -y openssh-serverRUN useradd -d /home/pramod -g root -G sudo -m -p $(echo “$PASS” | openssl passwd -1 -stdin) $NAMEEXPOSE 22CMD [“/usr/sbin/sshd”, “-D”] Save the file with Ctrl + X and press ‘Y’ Now run the below command to build a image from Dockerfile $ sudo docker build -t pramod . Run the below command to view Docker image $ sudo docker images Now create container from the pramod image $ sudo docker run -it –name redients pramod /bin/bash After running the above command, you are in container now, login in pramod user # su pramod Now you successfully logged in pramod and you can also check ssh status, ssh not running run the below commands # service ssh status# service ssh start

Docker file Read More »

Docker Port

Docker Port Docker Port Docker port is used to expose the running service inside the container to out side network.Let’s say you have deployed one Nginex or Apache Server container and inside the container one website is running on port 80. Now, you went to access the web page from out side of the container, then in this case, Port will useful for you. You need to expose or map a port out side running port. Docker Port commands To Check which port is exposed on a container $ sudo docker container lsor $ sudo docker port <container-id/name> In above image, you can see nothing is exposed on a container port. To Expose Port on container and run container in background $ sudo docker run -td –name <container-name> -p 80:80 <image-type> Example Now check the exposed port $ sudo docker port <container-name> Example

Docker Port Read More »

Chapter 3: Docker Volume and Docker Network

Docker Volume and Network Docker Volume Docker volume is simply a directory inside container or a persistence storage volume in container. Volume will be create, when you create a container.We can share a volume with other container also.Volume can be mapped/share in two ways Container to Container Host to Container Docker Network Docker Network is used establish communication between containers and host machine.Docker network can be created automatically and manually.Docker contains mainly three types of network. Bridge – default network Host – can be created or for standalone container Null – null or none can be used for not to provide communication to container Docker Volume Commands To List a Volumes $ sudo docker volume ls To Create a Volume $ sudo docker volume create <volume-name> To get Information about Volume $ sudo docker volume inspect <volume-name> Example:- To Mount Volume to a Container $ sudo docker run –mount source=[volume_name],destination=[path_in_container] [docker_image_name] To Run a Container and mount a volume then use this command $ sudo docker run -it –name=sredient –mount source=<volume-name>,destination=/<volume-name> <image-name> Example:- To Share volume from Host to container $ sudo docker run -it –name=sredient –mount source=<volume-name or volume-path>,destination=/<volume-name> <image-name> To Remove Volumes $ sudo docker rm <volume-name> To Remove all Unused volumes $ sudo docker prune Docker Network Commands To List a networks $ sudo docker network ls To know more opetions $ sudo docker network –help To connect a container to a network $ sudo docker connect <network-id/name> <container-id> To disconnect from a network $ sudo docker disconnect <network-id/name> <container-id> To create a network $ sudo docker network create -d <network-type> <network name> To know more about Create Command $ sudo docker network create –help To remove Network $ sudo docker network rm

Chapter 3: Docker Volume and Docker Network Read More »

Chapter 2: Docker Containers and Images

Docker Containers and Images Docker Containers What is a Container? Container is like a virtual machine which holds the entire packages that is needed to run the application. Containers are more portable and lightweight. What is Image in docker? Docker images are the read only binary templates used to create docker containers. Images become containers when they run on docker engine. Basic information about Container and Image Container ID:- 579c25a52e88Image:- UbuntuImage Name:- upbeat_panini Remember above information, It will help you to know, how the Container Id, Image type and Image name look likes. Basic commands for Docker Containers To list running containers $ sudo docker container psor$ sudo docker container ls To List all containers $ sudo docker container ps -aor $ sudo docker ps -a To start docker container $ sudo docker start <container-id> To Stop docker container $ sudo docker stop <container-id> To check containers Logs $ sudo docker logs -f <container-id> To go inside container $ sudo docker attach <container-id> To Remove a stopped container $ sudo docker rm <container-id> To Remove a running container $ sudo docker rm -f <container-id> To Remove all Stopped containers $ sudo docker rm $(docker ps -q -f “status=exited”) To Remove all Running containers $ sudo docker rm -f $(docker ps -aq) Basic commands for Docker Images To list Docker Images $ sudo docker images lsor $ sudo docker images ps To find images in Docker hub $ sudo docker search <image-name> To download the Docker images from Docker hub $ sudo docker pull <image-name> To build a Image from Dockerfile $ sudo docker build -t <image-name>:<tag-name> . To check the history of Image $ sudo docker history <image-name> To Export Docker Image $ sudo docker (image-name) >(filename).rar To Import Docker Images $ sudo docker <filename.rar> <image-name> To Push docker image in Docker hub $ sudo docker push <registory-name>/<username>/<image-name> To Remove docker Images $ sudo docker rmi <image-name> To Remove docker images forcefully $ sudo docker rmi -f <image-name> To Remove all docker images $ docker rmi $(docker images -q)

Chapter 2: Docker Containers and Images Read More »

Getting Started with Docker

Getting started with docker Docker Installation in Ubuntu Linux For the following Ubuntu Versions Ubuntu Jammy 22.04 (LTS) Ubuntu Impish 21.10 Ubuntu Focal 20.04 (LTS) Ubuntu Bionic 18.04 (LTS) If you have Older Docker version or already installed and went remove, then run the below commands Docker Remove Commands $ sudo apt-get remove docker docker-engine docker.io containerd runc $ sudo rm -rf /var/lib/docker /etc/docker$ sudo rm /etc/apparmor.d/docker$ sudo groupdel docker$ sudo rm -rf /var/run/docker.sock above commands will remove docker completely from your system Now let’s start installation of docker First update your system $ sudo apt-get update Run below command to install packages to allow apt to use a repository over HTTPS: Add docker repositories in your ubuntu system $ sudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release Now add docker official GPG key’s in your ubuntu system for this create separate directory for docker $ sudo mkdir -p /etc/apt/keyrings $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /etc/apt/keyrings/docker.gpg Now add the Docker Repository to APT sources list $ echo \ “deb [arch=$(dpkg –print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \$(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null Install Docker Engine $ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin Now docker is installed, check the docker status $ sudo systemctl status docker

Getting Started with Docker Read More »

Best DevOps tools in 2022

Top DevOps tools in 2022 1. Jenkins Jenkins is free and Open-source CI pipeline tool for DevOps. It automate the entire software development life cycle. It is community supported and might be your first choice tool for CI. 2. Docker Docker is an open-source centralised and containerization platform for DevOps. Docker allows you to create, deploy and run applications. Docker has fast and lightweight deployment containers and images. 3. Ansible Ansible is an open-source IT configuration management deployment and orchestration tools. Through ansible, your can install software’s, patches in network connected systems. Many DevOps engineers prefers Ansible to automate their infrastructure. 4. Git Git is a Source Code Management Tool.It is a free and open-source version control system. Git supports most of the version control features including check-in, commits, branches, merging, labels, push and pull from GitHub. 5. Kubernetes Kubernetes is an open-source container management tool which automates container deployment, container auto-scaling, networking and load balancing. It can create docker containers and deploy them for testing and production automatically.

Best DevOps tools in 2022 Read More »

wpChatIcon
    wpChatIcon