Skip to Content
Override ENTRYPOINT for a One-Off Job
Intermediate
0 likes
Tutorials

Override ENTRYPOINT for a One-Off Job

Run a different program from the same image with --entrypoint, in docker run and in Compose. After this, you can start a shell or a one-time job without rebuilding the image.

An image starts its main program, but sometimes you want something else from the same image just once: a shell to look around, a different script, a one-time cleanup. You do not need to rebuild the image or change its Dockerfile. You override the entrypoint for that one run. This page shows the plain Docker command and the Compose one.

An image with a fixed entrypoint

This image runs a small report script whenever it starts.

import sys
print("report for:", " ".join(sys.argv[1:]) or "everyone")
FROM python:3.14-alpine
COPY report.py /report.py
ENTRYPOINT ["python", "/report.py"]
CMD ["all customers"]
Set-Location job-demo
docker build -q -t job-demo-image:1 . | Out-Null
docker run --rm job-demo-image:1
docker run --rm job-demo-image:1 "March only"
report for: all customers
report for: March only

Words after the image name replace the CMD and go to the entrypoint as arguments. That is the normal use. It does not let you run anything else.

Override the entrypoint for one run

--entrypoint replaces the program. Everything after the image name then belongs to the new program. For a quick look around, use a shell.

docker run --rm --entrypoint sh job-demo-image:1 -c "ls /report.py && python --version"
docker run --rm --entrypoint python job-demo-image:1 -c "print('a one-off job in the same image')"
/report.py
Python 3.14.8
a one-off job in the same image

The image is the same, with the same files and libraries, and only the starting program changed. The setting is for that run and is not stored in the image. Two details: give the new entrypoint as a single program name, and put its arguments after the image name, not after --entrypoint.

⚠ Warning: --entrypoint takes only the program. Writing --entrypoint "python -c 1" as one string fails, because Docker looks for a program with that whole name.

The same in Compose

For a job you run again and again, such as a clean-up, define it as a service in the Compose file and run it on demand. docker compose run starts that one service, and --entrypoint overrides it for the run.

services:
  report:
    image: job-demo-image:1
Set-Location ..\job-stack
docker compose run --rm report 2>$null
docker compose run --rm --entrypoint sh report -c "echo shell inside the report service" 2>$null
report for: all customers
shell inside the report service

--rm removes the container when the job ends, so one-off containers do not pile up. A service with depends_on also starts its dependencies. Add --no-deps when you only want the job itself.

💡 Tip: Prefer a named service for a job you will repeat, so it is in the file and your team can read it. Use --entrypoint for the quick one-off you will never run again.

Clean up

docker image rm job-demo-image:1

Related course: Docker Intermediate.

About

Run a different program from the same image with --entrypoint, in docker run and in Compose. After this, you can start a shell or a one-time job without rebuilding the image.

Responsible
Christopher R
Last Update
08/07/2026
Reading Time
3 min
Was this helpful?
​ 0 ​ 0

Comments (0)

Sign in to comment

No comments yet.