I've built a Dockerfile with an entrypoint script that performs some validation checks. However, when I start an interactive terminal, the entrypoint script runs, which I'd like to avoid. I want to be able to see the output of the entrypoint script using 'docker logs ' without it automatically starting when I invoke bash. I've looked into init systems, but I think they might be overkill for my simple container. Any suggestions on how to achieve this? My Dockerfile ends with:
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/bin/bash"]
3 Answers
If your validation messages are logged to stdout/stderr, they should appear in your Docker logs by default. If you’re not seeing everything you expect, consider that Docker uses JSON as the default logging format. For troubleshooting, check the log file directly or use tools like 'jq' to parse the JSON logs for more details.
When you use both an ENTRYPOINT and CMD in your Dockerfile, the CMD becomes the arguments for the ENTRYPOINT. So when you run the container, it executes as "/entrypoint.sh /bin/bash". If you want to enter an interactive shell without triggering the entrypoint, you can override the ENTRYPOINT when starting the container by using --entrypoint. Here's how:
- To run the container and start a bash shell without the entrypoint, use this command:
```
docker run -ti --entrypoint /bin/bash myimage
```
- Alternatively, to run the container in the background with the entrypoint, use:
```
docker run -d myimage
```
- If you already have the container running and want to execute a bash shell inside it:
```
docker exec -ti /bin/bash
```
This way you can keep your entrypoint and still access your shell.
Thanks for the explanation! That makes a lot of sense. Just to clarify, when I drop into a bash shell using a few Linux server images, I don’t see any scripts running like I do in others like Pihole, but my logs show all the validation outputs. I'm trying to replicate that behavior in a simplified way.
To clarify on seeing scripts: when you drop into a bash shell, if you didn't specify it as your entrypoint, it's like starting a fresh instance without the validation checks running in the background. Make sure you're checking logs of the right container since launching a new instance only running bash won't show those.

You’re correct in noting that a Docker container remains active as long as there’s a process keeping it running. The reason other images can run scripts without displaying them is because they use a process manager like s6-overlay. In that case, the main process in the foreground manages everything, including your entrypoint. If using a simple bash script, consider structuring it to run your checks and then execute the main program or keep bash running.