1
0
mirror of /repos/baseimage-docker.git synced 2025-12-30 08:01:31 +01:00

Make docker-bash work on a regular sh shell instead of bash.

Closes GH-103.
This commit is contained in:
Hongli Lai (Phusion) 2014-07-13 12:49:43 +02:00
parent 2fa47a225b
commit 25e8b1c535
2 changed files with 11 additions and 11 deletions

View File

@ -1,6 +1,7 @@
## 0.9.12 (not yet released) ## 0.9.12 (not yet released)
* Added a workaround for Docker's inability to modify /etc/hosts in the container ([Docker bug 2267](https://github.com/dotcloud/docker/issues/2267)). Please refer to the README for details. * Added a workaround for Docker's inability to modify /etc/hosts in the container ([Docker bug 2267](https://github.com/dotcloud/docker/issues/2267)). Please refer to the README for details.
* The docker-bash tool now works on a regular sh shell too, instead of bash specifically. Closes GH-103.
## 0.9.11 (release date: 2014-06-24) ## 0.9.11 (release date: 2014-06-24)

View File

@ -1,11 +1,10 @@
#!/bin/bash #!/bin/sh
set -e set -e
set -o pipefail
KNOWN_HOSTS_FILE= KNOWN_HOSTS_FILE=
IP= IP=
function usage() usage()
{ {
echo "Usage: docker-bash <CONTAINER_ID> [COMMAND...]" echo "Usage: docker-bash <CONTAINER_ID> [COMMAND...]"
echo "Login to a Baseimage-based Docker container using SSH." echo "Login to a Baseimage-based Docker container using SSH."
@ -13,19 +12,19 @@ function usage()
echo "Otherwise, runs COMMAND inside the container." echo "Otherwise, runs COMMAND inside the container."
} }
function cleanup() cleanup()
{ {
local pids=`jobs -p` local pids=`jobs -p`
if [[ "$pids" != "" ]]; then if test "$pids" != ""; then
kill $pids kill $pids
fi fi
if [[ "$KNOWN_HOSTS_FILE" != "" ]]; then if test "$KNOWN_HOSTS_FILE" != ""; then
rm -f "$KNOWN_HOSTS_FILE" rm -f "$KNOWN_HOSTS_FILE"
fi fi
} }
if [[ $# = 0 ]]; then if test $# = 0; then
usage usage
exit exit
fi fi
@ -35,13 +34,13 @@ shift
trap cleanup EXIT trap cleanup EXIT
if ! [[ -e ~/.baseimage_docker_insecure_key ]]; then if ! test -e ~/.baseimage_docker_insecure_key; then
if [[ -e /usr/local/share/baseimage-docker/insecure_key ]]; then if test -e /usr/local/share/baseimage-docker/insecure_key; then
cp /usr/local/share/baseimage-docker/insecure_key ~/.baseimage_docker_insecure_key cp /usr/local/share/baseimage-docker/insecure_key ~/.baseimage_docker_insecure_key
else else
dir=`dirname "$0"` dir=`dirname "$0"`
dir=`cd "$dir/.." && pwd` dir=`cd "$dir/.." && pwd`
if [[ -e "$dir/image/insecure_key" ]]; then if test -e "$dir/image/insecure_key"; then
cp "$dir/image/insecure_key" ~/.baseimage_docker_insecure_key cp "$dir/image/insecure_key" ~/.baseimage_docker_insecure_key
else else
echo "*** ERROR ***: Baseimage-docker insecure key not found." >&2 echo "*** ERROR ***: Baseimage-docker insecure key not found." >&2
@ -72,7 +71,7 @@ if ! ssh -i ~/.baseimage_docker_insecure_key \
"root@$IP" "$@" "root@$IP" "$@"
then then
STATUS=$? STATUS=$?
if [[ $# = 0 ]]; then if test $# = 0; then
echo "----------------" echo "----------------"
echo "It appears that login to the Docker container failed. This could be caused by the following reasons:" echo "It appears that login to the Docker container failed. This could be caused by the following reasons:"
echo "- The Docker container you're trying to login to is not based on Baseimage-docker. The docker-bash tool only works with Baseimage-docker-based containers." echo "- The Docker container you're trying to login to is not based on Baseimage-docker. The docker-bash tool only works with Baseimage-docker-based containers."