Popular docker cmds Flashcards

1
Q

docker run -it ubuntu:latest bash

A

create a container with the latest ubuntu image running an interactive bash shell

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

How to list all active running containers

A

docker ps

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

how to see stopped containers

A

docker ps -a

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

docker run –rm “IMAGE NAME/ID”

A

remove the container after stopping, otherwise container will remain

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

How to attach/connect to a running container

A

docker attach docker run –rm “CONTAINER NAME/ID”

entering and exiting a bash container will shutdown the container

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

how to list last container closed

A

docker ps -l

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

how to name a new image?

A

docker tag “ID” “NEW IMAGE NAME”

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

How to commit new changes to a container to a new image and rename the new image

A

docker commit “CONTAINER NAME/ID”

This will create a new image, but with no name.

The original container will continue unaffected

will return a large number, that can be used to name the image:

docker tag <> <>

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

How to run docker with an interactive terminal?

A

docker run -it

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

How to run a detached container

A

Use -d flag with run

docker run -d <>

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

How to exit an attached container without stopping it

A

CTRL p CTRL q

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

How to start a new process in an existing container?

A

docker exec -ti <> <>

example:

docker exec -it <> bash

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

how to create a detached container?

A

docker -d

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

docker run -d “IMAGE NAME/ID”

A

How to create a detached container

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

How to start a stopped container?

A

docker start “CONTAINER NAME/ID”

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

How to restart a docker container?

A

docker restart “CONTAINER NAME/ID”

If the container is already stopped, then this cmd is the same as start

17
Q

How to stop a container

A

docker kill “CONTAINER NAME/ID”

this sends a SIGKILL to main process

or

docker stop “CONTAINER NAME/ID”

this sends a SIGTERM then a SIGKILL to main process

18
Q

How to look a logs for a container

A

docker logs “CONTAINER NAME/ID”

19
Q

How to remove a container?

A

docker rm “CONTAINER NAME/ID”

20
Q

How can you limit resource consumption by containers

A

Memory limits:

docker run –memory “CONTAINER NAME/ID”

CPU limits

docker run –cpu-share/–cpu-quota “CONTIANER NAME/ID”

21
Q

how to publish a port in docker

A

docker run -p hostpPort:containerPort

22
Q

how to list networks in docker

A

docker network ls

23
Q

how to list port mapping in a container?

A

docker port “CONTAINER NAME/ID”

24
Q

How to create a network?

A

docker network create “NETWORK NAME”

25
Q

How to create a container for a specific network?

A

docker run –net “NETWORK NAME/ID” “IMAGE NAME”