Docker Basic Commands Flashcards

1
Q

How to download a Docker image from docker hub?

A
docker pull "image-name"
e.g. docker pull ubuntu 
docker pull ubuntu:16.04 
docker pull busybox 
docker pull centos:6
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s the command to see offline Docker images?

A

docker images

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

What’s the command to see running Docker containers?

A

docker ps
OR
docker container ps

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

What’s the command to see all Docker containers?

A

docker ps -a | docker ps –all

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

How to run a docker container from a docker image?

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Command to know the number of docker images, Containers and other general Docker info?

A

docker info

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

How to get into a docker container?

A
  • Ensure container is running
  • Provide the following command
    docker exec -it “Container-ID” “Command”
    e.g. docker exec -it ubuntu:16.04 /bin/bas
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the stages of “run” command

A

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

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

What if you forgot to use -a with “docker start” command, how can you still see the output of docker start?

A

Yes, by using “docker logs” command.

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

What does “docker system prune” command does?

A

“docker system prune” removes all the “stopped” docker containers and resources like cache, network and images used by these containers

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

How to stop the running container?

A

Using “docker stop container-id”

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

Which Docker command is used to execute terminal commands in a running container?

A

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.

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