Section 2: Manipulating containers with docker client Flashcards

1
Q

What does this command do?:

docker run image1

A

The command will try to spin a docker from the image - image1. The steps involved are:

1) Docker CLI will pass on the control to docker daemon.
2) The docker daemon will search for the local cache for image1, if not present it would look for the image in docker hub and retrieve it if present,
3) After the image is retrieved, the file system snapshot in a docker image is copied to the hard drive in the local machine and resources for docker are reserved,
4) Then the start up command configured is run to execute the application / tool from the File System.

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

How do you execute a custom command using docker?

A

docker run image1 command.

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

What does docker ps show?

A

docker ps shows the currently running containers.

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

How do you check for containers that have you have run before using a command?

A

docker ps -a

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

What is the difference between docker run, docker create and docker start?

A

i) docker run = docker start + docker create
ii) docker create: Syntax: docker create image1 - Preps the docker with resources and File System from the image.
iii) docker start : Syntax: docker start container-id - starts the container with the container-id i.e executes the start up command. This will just output the container-id and not output from the docker.
To get the output from the running container we need to attach to the container with the container id using -a flag.

docker start -a container-id - output the information from docker.

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

Can we alter the start up command for a container that has run and exited using docker start command?

A

No, we cannot.

After we give docker start container-id, the container with previously set start up command will only run.

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

What is docker system prune?

A

Removes:

  • All stopped containers
  • All networks not used by at least one container
  • All dangling images
  • All build cache
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is docker logs container-id? Which use case is best suited to use this.

A

‘docker logs container-id’ is used to print out all outputs executed from the container before. We can use it in cases where

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

Can we set up a docker with a create command while creating it?

A

Yes we can.

We do it by issuing :
docker create container-id start-command

This sets up the docker to run the start-command above when run.

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

What are the ways to stop a running process in a container?

A

We can use:

docker stop container-id
docker kill container-id

The stop command gives the primary running process a buffer time of 10seconds to shutdown, and eventully runs a kill command. (Issues a SIGTERM command to the process)

The kill command instantly kills the primary running process in the docker.(Issues a SIGKILL command to the process.)

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

How do you execute an additional command in a docker?

Explain each term of that command.

A

docker exec -it container-id command

exec - execute a command
-it - gives the user option to input something to a container. (Or ability for the command started in the container to take input arguments from cli)
command - the command to execute.

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

docker exec -it container-id command

What does -it actually mean and how does it work?

A
  • it is actually a short notation for -i -t - basically two flags.
  • i means we are connecting our terminal to the input channel of the container and -t formats everything and makes the interaction readable. (refer google doc for diagram)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you get the shell type environment to work on with a docker?

A

docker exec -it container-id sh

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

How do you start a docker with a shell prompt?

A

docker run -it container-image sh

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