Docker Flashcards

1
Q

list all running containers

A

docker ps

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

list all containers (running and not running)

A

docker ps -a

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

stop one or more running containers

A

docker stop a123b

or use container name: docker stop silly_sherlock

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

run a new container from an image

A

docker run nginx

downloads the nginx image if it doesn’t exist

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

run a container in detached mode

A

docker run -d mycontainer

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

list all images stored locally

A

docker images

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

remove one or more images

A

docker rmi image_id

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

download an image from the repository without running

A

docker pull image_name

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

run a command in a running container

A

docker exec my_container command

docker exec my_container touch /tmp/newfile.txt

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

run a particular version of an image

A

docker run redis:6.2

use :version tag

Docker defaults to the latest tag (the most recent version)

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

run container in interactive mode

A

docker run -it ubuntu

-it allocates a pseudo-TTY

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

map a port on the container to a port on the host

A

docker run -p host:container image

docker run -p 80:3000 nginx

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

share data between the host and container (so data will persist if container is destroyed)

A

docker run -v hostdir:containerdir image

docker run -v /mydata:/var/lib/mysql mysql

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

display detailed info on a container, including config details, network settings, etc

A

docker inspect a123b4

docker inspect silly-sherlock <– or use the container name

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

fetch the logs of a container

A

docker logs a123b4

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

set an environment variable to be used by the app within your container

A

docker run -e myVAR=value image

16
Q

find the environment variable set on a container that’s already running

A

docker inspect a123b4

the json returned will include any environment variables set for the container in the config section

17
Q

how can I create my own image and install dependencies

A

use a Dockerfile

18
Q

create an image with a Dockerfile

A

docker build -t Dockerfile my-image-name