399 words
2 minutes

Docker Compose run: Put --entrypoint Before the Service Name

2026-11-27
DevOps
Docker
/
DevOps
/
Containers
/
Troubleshooting
Contents

If docker compose run app sh still invokes the service’s startup script, put --entrypoint before the service name to replace that script for the one-off container. Arguments after the service name fill the command and argument slots. They can reach the existing entrypoint even when the first argument looks like an executable or a Compose option.

The Compose run reference documents the order as docker compose run [OPTIONS] SERVICE [COMMAND] [ARGS...]. The distinction is easy to miss when the original entrypoint exits successfully after consuming the arguments.

See which process receives the arguments#

Save this as compose.yaml in an empty directory. The service uses printf as its entrypoint so the output exposes each received argument.

services:
app:
image: ubuntu:24.04
entrypoint: ["/usr/bin/printf", "entrypoint received: %s\n"]
command: ["default"]

Run these four variants from that directory. The comments show standard output. Compose also prints container lifecycle messages.

Terminal window
docker compose run --rm -T app
# entrypoint received: default
docker compose run --rm -T app /usr/bin/printf '%s\n' 'task ran'
# entrypoint received: /usr/bin/printf
# entrypoint received: %s\n
# entrypoint received: task ran
docker compose run --rm -T app --entrypoint /usr/bin/printf '%s\n' 'task ran'
# entrypoint received: --entrypoint
# entrypoint received: /usr/bin/printf
# entrypoint received: %s\n
# entrypoint received: task ran
docker compose run --rm -T --entrypoint /usr/bin/printf app '%s\n' 'task ran'
# task ran

In the last invocation, Compose selects /usr/bin/printf as the process to start and gives it the format string and message. In the third invocation, the original process receives --entrypoint as literal data. A successful exit in that third case only tells you that the original process completed.

The fixture was checked on November 27, 2026 with Docker Compose 5.1.3 and Docker Engine 28.4.0 on Linux arm64. Run docker compose down in the fixture directory to remove the project network afterward.

Choose whether to keep startup initialization#

Use docker compose run app <command> when the service’s entrypoint needs to prepare the environment and is designed to forward the command. Use docker compose run --entrypoint <executable> app <args> for a one-off task that can run without that startup logic. Specify any arguments required by the replacement executable explicitly.

For a shell in an already-running container, use docker compose exec app sh if the image includes sh. Compose exec starts the shell inside the existing service container. If the service is absent because of profile selection, check how Compose activates profiled services.

References:

Docker Compose run: Put --entrypoint Before the Service Name
https://laplusda.com/en/posts/docker-compose-run-override-entrypoint/
Author
Zero
Published at
2026-11-27
License
CC BY-NC-SA 4.0