kickstart/lib/kickstart-docker-create
Bruno Tavares c9633bb7b9 Add support for using different docker images
The part of trying out scripts involve creating a docker container with
ssh and running some projects and functions on it.

This change allows to define the docker image name to be used with the
docker-* functions.
2014-03-02 20:09:25 -03:00

30 lines
680 B
Bash
Executable File

#!/bin/bash -e
image_name=${1:-$KICKSTART_DOCKER_IMAGE}
image_name=${image_name:-moul/sshd}
pull_sshd_image() {
docker pull $image_name
}
remove_running_sshd() {
runnig_sshd=$(docker ps -q $image_name)
[ "$runnig_sshd" ] && docker kill "$runnig_sshd" && docker rm "$runnig_sshd"
true
}
run_sshd() {
id=$(docker run -p 22 -d $image_name)
[ -z "$id" ] && echo "Docker container did't start" && return 1
echo "Connect using root:root on " `docker port $id 22`
port=`docker port $id 22 | cut -f 2 -d :`
echo For ssh: kickstart docker-ssh
echo For deploy: kickstart deploy \"-p $port root@localhost\" '[roles]'
}
pull_sshd_image
remove_running_sshd
run_sshd