Create a dockerignore template for Python projects
Source: R/dockerignore-templates.R
dk_template_ignore_python.RdCreates a dockerignore template with patterns to ignore Python related files
and directories.
Details
This template adds patterns to ignore Python related files and directories, including:
__pycache__/: Compiled Python files*.py[cod]: Python compiled files.pytest_cache/: PyTest cache.coverage,htmlcov/: Coverage reports.tox/,.nox/: Testing environments.venv/,venv/,ENV/: Virtual environments.Python,build/,dist/: Build artifacts.egg-info/,*.egg: Package metadata.ipynb_checkpoints/: Jupyter notebook checkpoints
These files are typically not needed in a Docker image or can be regenerated during the build process. Ignoring them can significantly reduce the build context size.
See also
dk_template_ignore_node() for Node.js-specific patterns &
dk_template_ignore_common() for a more comprehensive template
Other dockerignore template functions:
dk_template_ignore_common(),
dk_template_ignore_data(),
dk_template_ignore_editor(),
dk_template_ignore_git(),
dk_template_ignore_node(),
dk_template_ignore_os(),
dk_template_ignore_packrat(),
dk_template_ignore_r(),
dk_template_ignore_raw_data(),
dk_template_ignore_renv()
Examples
# Create a new dockerignore with Python patterns
di <- dk_template_ignore_python()
# Add Python patterns to an existing dockerignore
di <- dockerignore() |>
di_add("*.log") |>
dk_template_ignore_python()