Docker Assignment– 7
Docker Best Practices
Basic Questions
- Create a new user and run a container as a non-root user.
- Run an image scan using docker scan and list vulnerabilities.
- Enable AppArmor for a container and inspect the applied profile.
- Run a container with a custom seccomp profile.
- Create a .dockerignore file and exclude unnecessary files from the build context.
- Build an image using Alpine as the base instead of Ubuntu.
- Build an image and verify layer caching by running two builds in sequence.
- Remove unused layers and dangling images using docker image prune.
- Run cAdvisor in a container and access its web UI.
- Run Prometheus in a container and configure it to scrape cAdvisor.
- Run Grafana in a container and add Prometheus as a data source.
- View container CPU and memory metrics in Grafana dashboards.
- Configure a container to log to a JSON file.
- Configure a container to log to syslog.
- Use docker logs to filter logs by timestamp.
- Compare docker logs with the JSON logging driver.
- Install Podman and run a container using it.
- Install Buildah and build an image without Docker.
- Install CRI-O and run a basic container workload.
- Write a short note on the differences between Docker, Podman, and CRI-O.
Intermediate Questions
- Run a container with limited privileges using the –cap-drop option.
- Configure Docker Content Trust (DCT) and pull only signed images.
- Build a multistage Dockerfile that compiles a Go app and produces a minimal runtime image.
- Use build cache mounts (–mount=type=cache) to speed up builds.
- Use cAdvisor to monitor disk usage of containers.
- Configure Prometheus to scrape metrics from multiple Docker hosts.
- Run Grafana and import a pre-built Docker monitoring dashboard.
- Configure a container to log to Fluentd and forward logs to Elasticsearch.
- Configure a container to log to AWS CloudWatch using a logging driver.
- Compare resource usage (CPU/memory) of the same app running on Docker vs Podman.
- Run a container with read-only filesystem enabled.
- Run a container with memory limit set to 256MB and verify behavior under stress.
- Enable restart policy on-failure with 3 retries for a critical container.
- Configure ulimits for a container and test its effect.
- Run an image scan with Trivy (alternative to docker scan).
- Create a Buildah script to build and push an image to Docker Hub.
- Run a microservice with Podman and compare commands with Docker.
- Create a Docker Compose file that includes Prometheus and Grafana services.
- Run a logging stack with Elasticsearch, Logstash, and Kibana (ELK) using Compose.
- Document best practices for optimizing and securing Docker images in a Markdown file.
Advanced Questions
- Build a CI/CD pipeline in Jenkins that builds a Docker image, scans it, and pushes it to a registry.
- Extend the pipeline to deploy the image as part of a Docker Compose stack.
- Add automated security scanning with Trivy or Clair in the CI/CD pipeline.
- Enable Content Trust in the pipeline to only push signed images.
- Deploy a microservice app (Frontend + Backend + Database) using Docker Swarm.
- Configure Prometheus and Grafana to monitor the microservice app.
- Configure Fluentd to collect logs from all services and forward them to Elasticsearch.
- Run a blue-green deployment of the backend service using Docker Swarm.
- Implement rolling updates for the frontend service using Swarm.
- Deliver a final project:
- Build a multi-container microservice app with Dockerfiles.
- Push images to a registry via CI/CD.
- Deploy stack using Compose and Swarm.
- Enable monitoring (cAdvisor + Prometheus + Grafana).
- Enable logging (Fluentd or ELK).
- Demonstrate security best practices (non-root, scans, signed images).