I am trying to disable the builtin kill
in the bash running inside the container, and I would like to know if it is possible to run a command after the container start running, or if it is possible to run /bash/bash
with some specific parameter to disable a builtin function.
I have a Dockerfile
with the following content:
...
ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "/bin/bash" ]
in the entrypoint.sh
, I have the following:
#!/bin/bash
exec "$@"
What I know is possible to do to disable kill
is run the command enable -n kill
and the builtin will be disabled. But this only works if I run the command inside the container (after exec
when I docker run).
Is there some way to disable the kill bultin in the entrypoint or in the Dockerfile?
2
Answers
A simple way is to put the
enable -n kill
command in the.bashrc
file of the user running the container.If you then interactively
exec
into the container,kill
doesn’t work.As I mentioned in the comments on your question, I think the only way to do this effectively (that is, in a way that isn’t easy for someone to re-enable the
kill
command) is to build a custombash
binary with thekill
command disabled.Here’s one option for that; we replace the
kill
builtin with a modified command that reportsThe kill command is not available in this shell.
when someone runskill
. This is a multi-stage Dockerfile — we perform the custom build in the first stage, and then copy just thebash
binary into the final image.Using this looks like: