Docker Commands Flashcards
What is “docker run” command?
The Docker run command is used
to run a container from an image. Running the docker run nginx command will run an instance of the nginx application on the Docker host if it already exists. If the image is not present on the host, it will go out to Docker hub and pull that image down.
What is the “docker ps” command?
The docker ps command lists all running containers and some basic information about them such as the container lD., the name of the image we used to run the containers, the current status, and the name of the container.
How is the ID and name created for the containers in docker?
Each container automatically gets a random lD. and name created for it by Docker
what is “docker stop” command?
To stop a running container, use the docker stop command, but you must provide either the container l.D. or the container name in the stop command. If you’re not sure of the name, run the docker ps command to get it.
What is the “docker rm” command?
Use the docker rm command to remove a stopped or exited container permanently.
How long does a container live?
Container only lives or is alive as long as the process running inside it.
Once the task is complete, the container exits. A container only lives as long as the process inside it is alive.
If the web service inside the container is stopped or crashed, then the container exits.
What command to use if you just want the image, but do not want to run a container using that image?
docker pull <image-name>
eg. docker pull ubuntu</image-name>
Docker command to remove an image?
docker rmi <image-name></image-name>
what does “docker images” command do?
Lists all the downloaded or locally available images
What are the two modes of running the “docker run” command
- Foreground or attached mode
- Detached mode
which is the default docker repository which has the official images?
library
what is the difference between exec and -it
docker exec is used to execute a command in a container and get the output in the std out.
-it option is used with docker run command and is used to get into the bash or get inside the container
What is docker run in detached mode
use that using -d option with docker run. That is used to have the docker container running in the background. You can get back to the prompt to run other commands in detached mode. In attached mode you will be attache dto the container not coming out of prompt to enter any other commands
Command to force kill a docker container?
docker stop <container-name></container-name>
command to remove a stopped or exited container permanently
docker rm <container-name></container-name>