Docker¶
Docker is a containerization platform that packages your simulation code and dependencies into portable, self-contained units called containers.
Docker enables consistent and isolated execution of simulations across different environments by:
- Packaging your solution code with all dependencies.
- Ensuring simulations run identically everywhere.
- Isolating each scenario run in its own container.
- Managing different solution versions through image tags.
Using Docker offers several key benefits:
- Reproducibility: same container image always produces the same results.
- Portability: run anywhere that supports Docker (local, cloud, Kubernetes).
- Dependency Management: all libraries and tools packaged together.
- Version Control: different versions coexist using different tags.
- Scalability: easily replicate containers for parallel execution.
- Isolation: each simulation runs independently without conflicts.
How it works¶
- Build: create a Docker image containing your solution code.
- Tag: version your image (e.g.,
my-solution:1.0.0). - Push: upload to Azure Container Registry.
- Register: reference the image in your Cosmo Tech solution.
- Execute: platform pulls and runs the container for each scenario.
Example Dockerfile¶
FROM python:3.11-slim
WORKDIR /app
# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy solution code
COPY src/ ./src/
# Run simulation
ENTRYPOINT ["python", "src/main.py"]
Image registry¶
Solutions reference Docker images stored in Azure Container Registry:
spec:
payload:
repository: myregistry.azurecr.io/my-solution
version: 1.0.0
alwaysPull: false
Best practices¶
- Use semantic versioning: tag images as
MAJOR.MINOR.PATCH. - Keep images small: use minimal base images (e.g.,
-slim,-alpine). - Don't hardcode secrets: use environment variables.
- Test locally first: run containers locally before deploying.
- Version alignment: solution version must match image tag.
Container execution¶
When a scenario runs:
- Kubernetes pulls the Docker image from the registry.
- Container starts with scenario parameters as environment variables.
- Your simulation code executes inside the container.
- Results are sent to Event Hub and stored in ADX.
- Container is cleaned up after completion.
Docker ensures your simulation runs consistently and reliably, regardless of where it is executed.
References¶
For more detailed information on Docker, please refer to: