Skip to content

Commit 1f9a55d

Browse files
committed
Dockerfile: fix and clean up shell prompt
The existing approach had some issues with how the control-chars were escaped; also switching to use Dockerfile here-doc to make it a bit more readable, and add some comments to the `.bashrc`. Also make sure the MOTD isn't printed multiple times, and only for interactive shells, and slightly tweak it with some colors. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 23d7346 commit 1f9a55d

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

dockerfiles/Dockerfile.dev

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,28 @@ RUN apk add --no-cache \
4747
jq \
4848
nano
4949

50-
RUN echo -e "\nYou are now in a development container. Run '\e\033[1mmake help\e\033[0m' to learn about\navailable make targets.\n" > /etc/motd \
51-
&& echo -e "cat /etc/motd\nPS1=\"\e[0;32m\u@docker-cli-dev\\$ \e[0m\"" >> /root/.bashrc \
52-
&& echo -e "source /etc/bash/bash_completion.sh" >> /root/.bashrc
50+
RUN <<-'EOF'
51+
cat > /etc/motd <<-'EOM'
52+
\e[1;32mYou are now in a development container.\e[0m
53+
54+
Run \e[1;36mmake help\e[0m to see available targets.
55+
EOM
56+
57+
cat >> /root/.bashrc <<-'EOB'
58+
# print the MOTD when opening the dev-container (interactive shell only).
59+
if [[ $- == *i* ]] && [[ -z "$MOTD_SHOWN" ]]; then
60+
printf "%b\n" "$(cat /etc/motd)"
61+
export MOTD_SHOWN=1
62+
fi
63+
64+
# set a custom prompt to make it more visible when inside the dev-container.
65+
PS1='\[\e[0;32m\]\u@docker-cli-dev\$ \[\e[0m\]'
66+
67+
# set-up bash completion for testing.
68+
source /etc/bash/bash_completion.sh
69+
EOB
70+
EOF
71+
5372
CMD ["/bin/bash"]
5473
ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
5574
ENV PATH=$PATH:/go/src/github.com/docker/cli/build

0 commit comments

Comments
 (0)