Write a Dockerfile for a cron-style job container that runs a script once and exits.
BeginnerHands-onWrite-a-Dockerfile tasks
Answer
FROM alpine:3.20
RUN apk add --no-cache bash curl jq aws-cli
COPY --chmod=0755 backup.sh /usr/local/bin/backup.sh
USER 65534:65534
ENTRYPOINT ["/usr/local/bin/backup.sh"]
Key trick → Don't run crond inside the container. Let the scheduler (a Kubernetes CronJob or an EventBridge rule plus ECS task) start it, and let the exit code report success. COPY --chmod avoids an extra RUN chmod layer.
More on Write-a-Dockerfile tasks
Write a production Dockerfile for a Node.js API using a multi-stage build.IntermediateWrite a Dockerfile for a Python Flask app that runs with gunicorn as a non-root user.BeginnerWrite a Dockerfile for a Go service that produces a tiny image (under 20 MB).IntermediateWrite a multi-stage Dockerfile for a Java Spring Boot app built with Maven.IntermediateWrite a Dockerfile for a static React site served by Nginx.BeginnerThis Dockerfile rebuilds dependencies on every code change. Fix it.Beginner