Introduction Flashcards

1
Q

What are containers

A

Isolated environments which helps in running multiple applications in a single machine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Difference between containers and VMs

A

VMs have their own OS KERNEL, however, container shares the Host OS Kernel

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Different between Docker and Docker Inc?

A

Docker: Container technology and Container Engine.

Docker Inc: Name of the organisation which open sourced container technology in public domain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Docker Engine Vs Docker Hub

A

Docker Engine: Container Engine required to run the containers.
Docker Hub: Image repository for saving Docker images created by the community.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Is it possible to run container engine of Windows on Linux?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to install Docker

A
  1. Download Docker installer
  2. Run Docker installer
  3. Verify installation by running “docker –version” command
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Instructions executed behind the scene, when we run

“docker run debian echo “hello world”?

A
  1. It checks for docker image “debian” in local repository.
  2. If found, it runs the container, if not, download same from Docker Hub and starts running it.
  3. After starting same, it runs echo command inside the container as the main process.
  4. Once “Hello world” execution gets completed, it stops the container
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When do container stops?

A

It stops when main process stops.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to run “interactive” session with container’s bash?

A

Using “-i” flag:

docker run -i debian /bin/bash

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to attach a “telewriter terminal - tty”, to a container?

A

Using “-t” flag

docker run -it debian /bin/bash

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to change the hostname of the container?

A

Using “-h” flag

docker run -it -h debian /bin/bash

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Does debian image contains all commands by default?

A

No, it contains only subset of commands.

It’s default location is /bin

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What will happen, if we delete the “/bin” directory?

A

The container will be useless, as there will be no commands to get execute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to list all the containers running in a machine with active state?

A

docker ps

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to list all the containers running in a machine with active and inactive state?

A

docker ps -a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to list all containers with some conditions?

A

docker ps -f

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How to print only IDs of the container during listing?

A

docker ps -q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is default name and ID of any container?

A

Default ID: AlphaNumeric code, which cannot be changed.
Name: Combination of two words separated by underscore.
First word: Adjective
Second word: Name of a famous scientist, Hacker or programmer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How to change the name of the container?

A

docker run –name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How to get detailed information about a container?

A

docker inspect

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Is it possible to extract required information from “docker inspect output” ?

A

The output of “docker inspect” command is a JSON.
By using go-lang template, we can extract information from “docker inspect”:
docker inspect –format {{.Network.ip}}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How to get logs from a container?

A

docker logs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What are different stages of container lifecycle?

A

running > exited > removed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How to remove a container without volume?

A

docker rm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

How to remove a container along it’s volume

A

docker rm -v

26
Q

How to get list of all containers available in “exited” state?

A

docker ps -aq -f status=exited

27
Q

How to remove “exited” or “stopped” containers?

A

docker -rm

28
Q

How to remove all containers available in “exited” state at once?

A

docker -rm -v $(docker ps -aq -f status=exited)

29
Q

How to get rid of container, once it’s stopped, during launch?

A

docker run -rm

30
Q

Installation cowsay and forture inside a container using interactive session and run same?

A

docker run -it debian /bin/bash
» apt-get update
» apt-get install -y htop cowsay fortune
» /usr/games/fortune | /usr/games/cowsay

31
Q

Define container image?

A

Set of instructions required to build and run the container

32
Q

Can we create an image from “running container”? iF yes how?

A

yes.

docker commit /

33
Q

How to create an image from “stopped container”?

A

docker commit /

34
Q

How to run a container from it’s image?

A

docker run /

35
Q

In which “format” instructions are provided in docker image?

A

It’s in “Name-Value” pair.

36
Q

What’s the purpose of the FROM instruction in Docker image file?

A

It provides the name of the base image from which we want to create our custom image.

37
Q

Explain RUN instruction?

A

It provides the instruction that we want to execute after base image.

38
Q

Explain COPY instruction?

A

Command for copying files from build context/host machine to container.

39
Q

Explain ENTRYPOINT instruction?

A

It takes any argument we pass from command line and pass it to the script we pass as entry point

40
Q

Create a Docker file for Cowsay application?

A

FROM debian

USER root
RUN apt-get upgrade
RUN apt-get install fortune -y
RUN apt-get install cowsay fortune -y
COPY entrypoint.sh /
ENTRYPOINT [ "/entrypoint.sh"]
41
Q

How to build a container from docker file?

A

docker build -t

42
Q

Explain the composition of “path” used by the Docker to find an image?

A

Registry: Name of the service where Docker looks for the image.
Repository: Main repository which contains our image
Tag: version of the image

43
Q

What are the different components gets installed, when we install Docker?

A
  1. Docker daemon
  2. Docker cli
  3. Docker client
44
Q

What are the functions of Docker daemon?

A
  1. Creation of containers
  2. Execution of containers
  3. Monitoring of containers
  4. Creation of images
  5. Distribution of images
45
Q

What is Docker cli?

A

Command line interface to interact with Docker daemon

46
Q

What is Docker client?

A

Http client to communicate with the Docker Daemon over http protocol.

47
Q

How to start the Docker, if it’s not running?

A

Docker daemon init

48
Q

Relation with Docker engine and Docker daemon?

A

Docker engine is subset of Docker Daemon

49
Q

What is build context?

A

Set of files or folders passed to the Docker daemon during build process

50
Q

What is generally passed in build context?

A

Generally, same folder is passed as build context which contains the docker file.

51
Q

In which format, build context is passed to the Docker daemon?

A

in the form of “tar” ball.

52
Q

What will happen if we pass “/” as build context?

A

The process will be very long, as all folders and machines will be passed to the Docker daemon

53
Q

Why we need the build context?

A

It is required to copy files from context to the container?

54
Q

How to ignore files from build context?

A

By provide the .dockerignore file

55
Q

What is done by docker ignore file?

A

It ignore all the files available in build context, during image build process.

56
Q

what’s the image creation process?

A

The image is created layer by layer where each layer represents a single instruction:
1. The first image is created by using FROM instruction
2. The second image is created on TOP of above image by RUN instruction
3. The third image is created on TOP of second image and after successful creation, second layer is deleted.
This process continues, until all image gets completed.

57
Q

What’s the command to find history of image creation?

A

docker history

58
Q

How to provide information of the Author inside the Docker file?

A

By using MAINTAINER instruction

59
Q

How to add environment variables in images?

A

By using ENV instruction

60
Q

How to expose the listening port of the application running inside the container?

A

EXPOSE 8080

61
Q

How to mention working directory of container inside the Docker file?

A

By using WORKDIR instruction

62
Q

What’s the instruction to provide user name inside the docker file?

A

by using USER instruction