Docker run Flashcards

1
Q

What to use if you want to run a container of Redis but with a specific version?

A

use tags

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

What is the default tag for every image?

A

latest

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

Where to find the supported tags of an image?

A

in docker hub, for each image you can see list of supprted tags

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

How to attach the Standard input (STDIN) to a docker container?

A

That is because, by default, the docker container does not listen to a standard input. Even though you’re attached to its console, it is not able to read any input from you. It doesn’t have a terminal to read inputs from. It runs in a non-interactive mode. If you would like to provide your input, you must map the standard input of your host to the docker container using the -i parameter.

eg. docker run -i kodekloud/web-server

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

what is -t option with docker run command?

A

The -t stands for pseudo terminal. So, with the combination of -i and t, we’re now attached to the terminal as well as in an interactive mode on the container.

eg. docker run -it kodekloud/web-server

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

what is the underlying host where docker is installed is called?

A

docker host or docker engine

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

How to do port mapping in docker run command?

A

docker run -p 80:5000 kodekloud/webapp

80: is the port on the docker host
5000: is the port on the container

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

What happens when you don’t port map and just run a web app in a container?

A

The webserver will run in the container, in the internal IP which is internal to the container.
Can only be accessed from the docker host where container is running.

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

What to do if a web server is running in a container, but that webserver has to be accessed from outside the docker host?

A

By default the container will have an internal IP, can be accessed only from the docker host. Users outside of the docker host cannot access it using this IP. For this, we could use the IP of the docker host. But for that to work, you must have mapped the port inside the docker container to a free port on the Docker host.

eg. docker run -p 80:5000 kodekloud/webapp

80 is the free port on the docker host
5000 is the internal port on the container where the web server is running

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

What is the benefit of port mapping between the docker container and docker host?

A

You can run many instances of the same application using different ports. For eg, below mysql server, many instances are being run using different ports:

docker run -p 3306:3306 mysql
docker run -p 8306: 3306 mysql

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

What happens if you try running an application using same port mapping twice? Port mapping between docker container and docker host?

eg.
docker run -p 8306: 3306 mysql
docker run -p 8306: 3306 mysql

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

Diagram to explain docker port mapping?

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

With docker run command how to run a Ubuntu container but also get an output before the container is exited?

A

docker run ubuntu cat /etc/hosts

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

How to append a tag in run command

A

using the :
eg. docker run ubuntu:16.04

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

docker run command to run the container in detached mode?

A

docker run -d <image></image>

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

docker command to connect to a container?

A

docker attach <container-name></container-name>

17
Q

How to find the internal IP assigned to a docker container?

A

docker inspect <container-id></container-id>

18
Q

What do you have to do to persists the changes and configuration of the container?

A

Map the volumes using -v option in docker run command

19
Q
A