liveBook · Manning

Dockerignore

As explained in Build Python Web Apps with Streamlit

.dockerignore is a Docker configuration file that specifies files and directories excluded from a build context or image.

A .dockerignore file controls which files and directories Docker excludes while copying a project into an image. Use it to keep secrets and unrelated metadata out of shareable image artifacts. section 12.2.4

Exclude secrets and project metadata

Create .dockerignore beside the Dockerfile. A practical starting point excludes the .streamlit/ directory, where secrets.toml may live, along with Python caches and Git metadata. section 12.2.4

Listing 12.3 The .dockerignore file
__pycache__/
.git/
.gitignore
.streamlit/

The example lists patterns for excluding __pycache__/, .git/, .gitignore, and .streamlit/ during an image build. section 12.2.4

Extend the file when deployment creates additional sensitive configuration:

  • Add .ebextensions/ so deployment configuration containing secrets is not copied into the image. section 12.3.5
  • Add .elasticbeanstalk/ before initializing Elastic Beanstalk, because the directory will be generated later. section 12.3.5

How Build Python Web Apps with Streamlit covers it

How deep it goes
Defines pattern-based exclusions with concrete entries but stops short of detailing Docker’s matching rules.
Examples
Uses exclusions for __pycache__/, .git/, .gitignore, .streamlit/, .ebextensions/, and .elasticbeanstalk/.
What it assumes
Assumes familiarity with Docker image builds, COPY instructions, and basic Git-style ignore patterns.
What you can do after
Configure Docker builds to prevent secrets and deployment files from entering shareable image artifacts.
How it connects
Connects Docker images with Dockerfiles, .gitignore, Streamlit secrets, and Elastic Beanstalk configuration.

Also explained in

Compare how 4 books explain dockerignore →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.