Debug School

Mohammed Zaid
Mohammed Zaid

Posted on

Docker Assignment 1

  1. What is Docker and why is it used?

Docker is a platform that is used for developing, shipping, and running applications. It provides the ability to package and run an application in a a virtual environment called "container".

  1. What is a Docker image and how is it different from a Docker container?

A Docker image contains set of instructions for creating a container that can run on the Docker.
The difference between Docker image and a Docker container is that a Docker image defines how a container will be built whereas a Docker container is an instance of a Docker image.

  1. How do you create a Docker image and run a Docker container?

There are two ways to create docker image:

  • Using Existing Container: Image = Ubuntu + git + + apache2 + java

784 docker run -itd --name zaid ubuntu
785 docker ps
786 docker exec -it c60e9072a1b0 /bin/bash
787 docker ps
788 docker exec c60e9072a1b0 zaid
789 docker exec c60e9072a1b0 git
790 clear
791 ls
792 docker ps
793 docker exec c60e9072a1b0 which apache2
794 docker commit -m"ub-up-git-apa" -a"Zaid" c60e9072a1b0 ub-up-git-apa
795 docker images
796 docker run -itd ub-up-git-apa
797 docker ps
798 docker exec d823ff6a026b git
799 docker exec d823ff6a026b which apache2

INSIDE A CONTAINER
1 apt-get install git
2 apt-get update
3 clear
4 git
5 apt-get install git
6 git
7 clear
8 apt-get install apache2
9 clear
10 which git
11 which apache2
12 exit

  • Using Dockerfile: FROM ubuntu MAINTAINER Zaid DevOps@rajeshkumar.xyz RUN apt-get update RUN apt-get install git -y RUN apt-get install apache2 -y

FROM ubuntu

MAINTAINER Zaid DevOps@zaid.xyz
RUN apt-get update && apt-get install git -y && apt-get install apache2 -y

  1. What is a Dockerfile and how do you use it to create a Docker image?

A Dockerfile is a script that contains instructions using which a Docker image can be built.
To create a image using dockerfile:

FROM ubuntu

MAINTAINER Zaid DevOps@rajeshkumar.xyz
RUN apt-get update
RUN apt-get install git -y
RUN apt-get install apache2 -y

FROM ubuntu

MAINTAINER Zaid DevOps@zaid.xyz
RUN apt-get update && apt-get install git -y && apt-get install apache2 -y

  1. How can you inspect the contents of a Docker container and the changes made to a container while it was running?

By using "inspect command", we can the contents of a Docker container and the changes made to it.

Ex: docker inspect eef958b5b633

  1. How can you share a Docker image with others and pull an image from a Docker registry?'
  • Create a repository on any registry such as hub.docker.com
  • Login to the repository on terminal using "docker login"
  • The name of the docker image that you want to share and the repository should be the same. If not the create an alias of the image with the same name as of the repository using command "docker tag imagename repositoryname". Ex- docker tag ub-up-git-ap-db devopsschools/wed22023.
  • Push the image on the repository using the command "docker push imagename".

We can pull an image from a Docker registry by using "docker pull" command.

  1. What are the different network modes available in Docker and how do you choose the right network mode for your application?

There are three different network modes available in Docker:

  • bridge networks-> it is used within a single host
  • overlay networks-> it is used for multi-host communication
  • macvlan networks-> it is used to connect Docker containers directly to host network interfaces
  1. How can you mount a volume in a Docker container and share data between the host and container?

To mount a volume in a docker container, we use the command "docker run itd -v path", where path is the location of volume.

  1. What is the difference between a Docker Compose file and a Dockerfile, and how are they used in deploying multi-container applications?

A Dockerfile is a text file that contains the commands that a user can execut to build an image.
Docker Compose is a tool for defining and running multi-container Docker applications.

  1. How can you monitor the performance of a Docker container and diagnose issues with it?

We can monitor the performance of a docker container by executing the command "docker stats".

  1. Components of Docker and its Brief Summary.
  • Docker Engine: Docker Engine is a containerization technology that is used to build and containerize applications.
  • Docker Image: A Docker image contains set of instructions that are used to create a container.
  • Docker Registry: A Docker registry is a storage system for Docker images.
  • Docker container: Docker containers are standardized, executable components that combine application source code with the operating system and dependencies that are required to run the code in any environment.
  1. What is the different between docker pause and unpause?
  • The docker pause command is used to suspend all processes in the specified containers.
  • The docker unpause command un-suspends all processes in the specified containers.
  1. What is the different between docker stop and kill?

The docker stop command stops the container and provides a safe way to stop the container whereas docker kill command kills one or more containers.

  1. What is the different between docker exec and attach?

The docker exec command is used to run a new command in a running container whereas docker attach command is used to attach the terminal's standard input, output, and error to a running container.

  1. List of dockerfile instructions and its Brief Summary?
  • FROM: This command is used to create a base image such as an operating system, a programming language, etc.
  • RUN: A RUN instruction is used to run specified commands.
  • COPY: This instruction is used to copy a directory from our local machine to the docker container.
  • WORKDIR: It is used to specify our working directory inside the container.
  • CMD:This command is used to run a docker container by specifying a default command that gets executed for all the containers of that image by default.
  1. What is the differenet between CMD vs Entrypoint?

CMD: This command is used to run a docker container by specifying a default command that gets executed for all the containers of that image by default.
Entrypoint: This instruction is used to configure the executables that will always run after the container is initiated.

Top comments (0)