Docker Community Forums

Share and learn in the Docker community.

How exactly does the entrypoint script bash work

So I followed the guide to add an entryscript into the Dockerfile
ADD shell.sh /home/shell.sh
RUN chmod +x /home/shell.sh

EXPOSE 80/tcp 443/tcp

ENTRYPOINT ["/home/shell.sh"]

And because I don’t want the container to exit instantly, I added a /bin/bash to hold the container.
[…]
/bin/bash

Now here’s something which I don’t understand happens:
After the container runs, it will go into the bash.
You can type exit once, and exit once to another layer of bash, will be able to reattach, but if you type exit again, the other layer of bash exits and container stops.
However, if I remove the /bin/bash and run container, it exits instantly after the entrypoint is done.

So it’s either bash inside bash or 1 bash but exits instantly(the interface will show, but instantly exits).

My starting arguments:
docker run
–detach
–tty
–interactive
–network staticnetwork
–ip 172.11.0.230
–name $CONTAINER_NAME
$IMAGE_NAME
( equivalent to -dit some post suggests )

To add, just checked again and when a bash is run, when I top in the container I do see 2 bashes.

1 root       20   0   18376   3072   2828 S   0.0  0.0   0:00.18 shell.sh
25 root      20   0   18508   3420   3012 S   0.0  0.0   0:00.14 bash
36 root      20   0  141108   1544     64 S   0.0  0.0   0:00.00 nginx
37 www-data  20   0  141484   3380   1680 S   0.0  0.0   0:00.00 nginx
38 www-data  20   0  141484   3380   1680 S   0.0  0.0   0:00.00 nginx
39 www-data  20   0  141484   3380   1680 S   0.0  0.0   0:00.00 nginx
41 www-data  20   0  141484   3380   1680 S   0.0  0.0   0:00.00 nginx
42 root      20   0   18508   3204   2916 S   0.0  0.0   0:00.00 bash
47 root      20   0   36620   3124   2628 R   0.0  0.0   0:00.00 top