Created
February 26, 2015 08:11
-
-
Save kneradovsky/6674ba2f9d190ab7b507 to your computer and use it in GitHub Desktop.
Docker image with ssh server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NAME=linuxserver | |
MASTER_NAME=sshd | |
if [[ -z "$2" ]]; then | |
EXTERNAL_PORT=2022 | |
else | |
EXTERNAL_PORT=$2 | |
fi | |
export NAME=$NAME | |
export EXTERNAL_PORT=$EXTERNAL_PORT | |
sudo -E /opt/docker-runners/runners-default/master-$MASTER_NAME $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM oraclelinux:6.6 | |
MAINTAINER Konstantin Neradovsky "kneradovsky@gmail.com" | |
RUN yum install -y openssh-server sudo passwd | |
ADD run /usr/local/bin/run | |
ADD adminuser /etc/sudoers.d/adminuser | |
RUN ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa | |
RUN ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa | |
RUN echo 123qweasd | passwd --stdin root | |
RUN useradd -G root adminuser | |
RUN echo 123qwe | passwd --stdin adminuser | |
RUN chmod +x /usr/local/bin/run | |
CMD ["/usr/local/bin/run"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOGS="tail -n 200 -f /var/log/messages" | |
CONSOLE="bash" | |
INTERNAL_PORT=22 | |
PREFIX=sshdserver | |
CID=$EXTERNAL_PORT | |
HELP_MESSAGE="USAGE: $NAME <start, stop, remove, logs, console or status> [ID]" | |
if [[ -z "$1" ]]; then | |
echo $HELP_MESSAGE | |
exit 0 | |
fi | |
if [ $1 == "start" ]; then | |
docker run -p $EXTERNAL_PORT:$INTERNAL_PORT --privileged -d -t --name $NAME-$CID oraclelinux:$PREFIX | |
docker start $NAME-$CID | |
echo "container started" | |
elif [ $1 == "stop" ]; then | |
docker stop $NAME-$CID | |
echo "Container stopped" | |
elif [ $1 == "remove" ]; then | |
docker stop $NAME-$CID | |
docker rm $NAME-$CID | |
echo "container removed" | |
elif [ $1 == "status" ];then | |
docker ps|grep "NAMES" && docker ps -a|grep "$NAME-$CID" | |
elif [ $1 == "logs" ];then | |
lxc-attach -n `sudo docker inspect $NAME-$CID | grep '"ID"' | sed 's/[^0-9a-z]//g'` -- $LOGS | |
elif [ $1 == "console" ];then | |
lxc-attach -n `sudo docker inspect $NAME-$CID | grep '"ID"' | sed 's/[^0-9a-z]//g'` -- $CONSOLE | |
else | |
echo $HELP_MESSAGE | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
exec /usr/sbin/sshd -D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why
Sometime you need discardable environment to play with. Docker containers could be lightweight alternative to the regular vm snapshots. The container will start ssh server in foregorund letting you to login inside from outside of the docker host.
How to use
5 . start docker using ./container-run start if portnum is omitted default value 2022 is used