When you run a Docker container, it typically follows a predefined entrypoint defined in its Docker image. This entrypoint is responsible for starting up the application or service configured by the image. In many cases, this script also performs initial setup tasks such as environment configuration, file generation, or permission adjustments before launching the main process. However, you may need to override the entrypoint if you want to bypass the default behavior - perhaps to debug the container, explore its file system, or run a different command.
For example, in the official nginx
image, the default entrypoint script sets up environment variables and launches the Nginx web server. Here's what happens by default:
docker run -it --rm nginx
Output (truncated):
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2025/07/14 07:47:19 [notice] 1#1: using the "epoll" event method
2025/07/14 07:47:19 [notice] 1#1: nginx/1.29.0
2025/07/14 07:47:19 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14+deb12u1)
2025/07/14 07:47:19 [notice] 1#1: OS: Linux 6.8.0-60-generic
2025/07/14 07:47:19 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2025/07/14 07:47:19 [notice] 1#1: start worker processes
...
This runs the Nginx startup process as defined in /docker-entrypoint.sh
. But sometimes you don't want Nginx to start - you might just want to open a shell inside the container. That's where overriding the entrypoint comes in.
To override the entrypoint, use the --entrypoint
option:
docker run -it --rm --entrypoint /bin/bash nginx
What this does:
- It replaces the default
/docker-entrypoint.sh
with/bin/bash
. - The Nginx startup process is skipped.
- You're dropped into a shell, where you can explore the container manually.
Leave a Comment
Cancel reply