Docker Basic Commands Flashcards
How to download a Docker image from docker hub?
docker pull "image-name" e.g. docker pull ubuntu docker pull ubuntu:16.04 docker pull busybox docker pull centos:6
What’s the command to see offline Docker images?
docker images
What’s the command to see running Docker containers?
docker ps
OR
docker container ps
What’s the command to see all Docker containers?
docker ps -a | docker ps –all
How to run a docker container from a docker image?
docker run -it "Image-name" "optional command" e.g. docker run -it busybox docker run -it busybox ls docker run -it busybox echo "Hey there!" docker run -it ubuntu:16.04
Command to know the number of docker images, Containers and other general Docker info?
docker info
How to get into a docker container?
- Ensure container is running
- Provide the following command
docker exec -it “Container-ID” “Command”
e.g. docker exec -it ubuntu:16.04 /bin/bas
What are the stages of “run” command
run command = create container + start container
so “docker run -it busybox” is equivalent to
docker create “image name”
docker create busybox – provides you a long alphanumeric key
and
docker start -a “alphanumeric key”
“-a” is for displaying the output on screen (STDOUT) when that container starts, else there will be no output
What if you forgot to use -a with “docker start” command, how can you still see the output of docker start?
Yes, by using “docker logs” command.
What does “docker system prune” command does?
“docker system prune” removes all the “stopped” docker containers and resources like cache, network and images used by these containers
How to stop the running container?
Using “docker stop container-id”
Which Docker command is used to execute terminal commands in a running container?
docker exec -it “container-id” “terminal command”
e.g
docker exec -it 28d73bdcb05e /bin/bash
If you need to put this process in the background, use -itd, instead of just -it. “d” here is deamon means background process.