docker Flashcards

(19 cards)

1
Q

To run a docker image

A

press the run button in the UI

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

A docker container is basically

A

a background process thats running an image. Like a server.

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

An image is

A

all the code of the OS (binaries, config), the dependencies, and anything you copied in.

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

To create a new image, you need to

A

create a Dockerfile

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

The FROM section in the Dockerfile defines

A

which parent image your new image will start from.

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

The EXPOSE section in the Dockerfile defines

A

the port in your container will be allowed to be proxied to the outside world.

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

To make a docker container accept requests on a particular port, you need to

A

put EXPOSE 8000 in the dockerfile so it will be permitted to to share that port.
Run the docker image in a container and set a host proxy port which will map to the EXPOSE port.

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

For development, to get updates to project files to get seen by the docker image, you need to use

A

a volume

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

a volume is

A

a path to a directory that your container will be able to access in real time from your main computer in its container. A portal.

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

A dockerfile is basically

A

the list of instructions for creating a new docker image

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

Before deploying, you must

A

remove your volume and create a new image with the files actually copied into the image.

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

Volumes do not

A

save into the image.

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

The COPY section in the dockerfile defines

A

files to copy from the local computer to the container computer.

e.g. COPY myDir /myContainerDir

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

The CMD section in the dockerfile defines

A

a command you want to run in the container’s WORKDIR
Must be a list of arguments
e.g. CMD [‘echo’, ‘string’]

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

the WORKDIR section in the dockerfile defines the

A

folder that you want docker to create and cd into so it is the working directory. Basically mkdir my_directory and cd my_directory combined.
CMD commands will run in the WORKDIR

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

the ADD section in the dockerfile defines

A

a file that you want copied into the image

17
Q

ADD and COPY are the same except

A

ADD can also accept a URL

18
Q

A base image is

A

the first image in a lineage of parent images

19
Q

Simplest example app

A

Copied separately from main.py because each step creates a cache

  • Dockerfile
    FROM python:3.9-slim-buster
    WORKDIR /my_app
    COPY requirements.txt .
    RUN [“pip”, “install”, “-r”, “requirements.txt”]
    COPY main.py .
    EXPOSE 8000
    CMD [“python”, “main.py”]
  • main.py
    from flask import Flask

app = Flask(__name__)

@app.get(“/”)
def index():
return “<h1>Hello, world!</h1>”

if __name__ == “__main__”:
app.run(host=”0.0.0.0”, port=8000)

  • requirements.txt
    Flask==3.0.3

Then build the image
docker build -t my_image_name ./path/to/project_dir

And run it from docker desktop using a proxy host port