Docker run Flashcards
What to use if you want to run a container of Redis but with a specific version?
use tags
What is the default tag for every image?
latest
Where to find the supported tags of an image?
in docker hub, for each image you can see list of supprted tags
How to attach the Standard input (STDIN) to a docker container?
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
what is -t option with docker run command?
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
what is the underlying host where docker is installed is called?
docker host or docker engine
How to do port mapping in docker run command?
docker run -p 80:5000 kodekloud/webapp
80: is the port on the docker host
5000: is the port on the container
What happens when you don’t port map and just run a web app in a container?
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.
What to do if a web server is running in a container, but that webserver has to be accessed from outside the docker host?
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
What is the benefit of port mapping between the docker container and docker host?
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
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
Diagram to explain docker port mapping?
With docker run command how to run a Ubuntu container but also get an output before the container is exited?
docker run ubuntu cat /etc/hosts
How to append a tag in run command
using the :
eg. docker run ubuntu:16.04
docker run command to run the container in detached mode?
docker run -d <image></image>