Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Dockerfile for a simple Flask Project | Docker for Flask
Docker for Python Developers

bookDockerfile for a simple Flask Project

To package our project into a Docker container, we need an additional command: WORKDIR.

FROM python:3.9-slim

# Set the working directory inside the container
WORKDIR /flask-app

COPY . .
RUN pip3 install -r requirements.txt

# Set the command to run the Flask application
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]

The WORKDIR command in Docker sets the working directory for any subsequent instructions in the Dockerfile. In your case, WORKDIR /flask-app sets /flask-app as the working directory.

This means that any further instructions (such as COPY, RUN, CMD, etc.) will be executed in the context of this directory. For example, if you execute COPY app.py /flask-app, the file app.py will be copied into the /flask-app directory inside the container.

This is useful for organizing your project within the container and ensuring clarity about where operations are taking place within the Docker image.

question mark

What does the WORKDIR command in Docker do?

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 3

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Awesome!

Completion rate improved to 5.88

bookDockerfile for a simple Flask Project

Stryg for at vise menuen

To package our project into a Docker container, we need an additional command: WORKDIR.

FROM python:3.9-slim

# Set the working directory inside the container
WORKDIR /flask-app

COPY . .
RUN pip3 install -r requirements.txt

# Set the command to run the Flask application
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]

The WORKDIR command in Docker sets the working directory for any subsequent instructions in the Dockerfile. In your case, WORKDIR /flask-app sets /flask-app as the working directory.

This means that any further instructions (such as COPY, RUN, CMD, etc.) will be executed in the context of this directory. For example, if you execute COPY app.py /flask-app, the file app.py will be copied into the /flask-app directory inside the container.

This is useful for organizing your project within the container and ensuring clarity about where operations are taking place within the Docker image.

question mark

What does the WORKDIR command in Docker do?

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 3
some-alt