Preview:
@echo off

SET %DOCKER%=”docker”

SET CONTAINER_NAME=”linux_sandbox”
SET IMAGE_TO_USE=”centos:latest”
SET IMAGE_TO_USE_SANDBOX=”sandbox:%CONTAINER_NAME%”

echo Container – %CONTAINER_NAME%
echo Select an Option to Continue:
echo [0] – Container – Create
echo [1] – Container – Start
echo [2] – Container – Stop
echo [3] – Container – Terminal
echo [4] – Container – Destroy

set /p CHOICE=”Enter Selection: ”

IF “%CHOICE%” == “0” (
%DOCKER% pull “%IMAGE_TO_USE%”

start /MIN “” “%DOCKER%” run -it –privileged –name %CONTAINER_NAME% %IMAGE_TO_USE% bash

timeout 10

%DOCKER% exec -it %CONTAINER_NAME% bash -c “yum -y update;yum clean all”
%DOCKER% exec -it %CONTAINER_NAME% bash -c “yum -y install openssh-server passwd; yum clean all”
%DOCKER% exec -it %CONTAINER_NAME% bash -c “mkdir /var/run/sshd”
%DOCKER% exec -it %CONTAINER_NAME% bash -c “ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ””
%DOCKER% exec -it %CONTAINER_NAME% bash -c “echo ‘root:password’ | chpasswd”

%DOCKER% commit %CONTAINER_NAME% %IMAGE_TO_USE_SANDBOX%
%DOCKER% stop %CONTAINER_NAME%
%DOCKER% rm %CONTAINER_NAME%

%DOCKER% run -d –privileged –name %CONTAINER_NAME% -p “22:22” %IMAGE_TO_USE_SANDBOX% /usr/sbin/sshd -D
)

IF “%CHOICE%” == “1” (
%DOCKER% start %CONTAINER_NAME%
)

IF “%CHOICE%” == “2” (
%DOCKER% stop %CONTAINER_NAME%
)

IF “%CHOICE%” == “3” (
%DOCKER% exec -it %CONTAINER_NAME% /bin/bash
)

IF “%CHOICE%” == “4” (
%DOCKER% stop %CONTAINER_NAME%
%DOCKER% rm %CONTAINER_NAME%
%DOCKER% rmi %IMAGE_TO_USE_SANDBOX%
)

pause
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter