ssh-add ~/.ssh-from-host/github_rsa
REM Share your host `~/.ssh` directory to `/root/.ssh-from-host`
REM You can use `ssh-add ~/.ssh-from-host/github_rsa` now
echo off
setlocal enableDelayedExpansion
set SSH_CERT_DIR=%userprofile:\=/%
set SSH_CERT_DIR=%SSH_CERT_DIR:C:/=//c/%
set SSH_CERT_DIR=%SSH_CERT_DIR%/.ssh/
REM echo %SSH_CERT_DIR%
for /f "delims=" %%a in ('docker container inspect ee-ubuntu1 --format="{{.Id}}"') do set DOES_CONTAINER_ALREADY_EXIST=%%a
REM echo %DOES_CONTAINER_ALREADY_EXIST%
if "%DOES_CONTAINER_ALREADY_EXIST%" == "" (
echo "Creating ee-ubuntu1 container"
REM Use the start command so the rest of the batch script continues to run
start docker run --name=ee-ubuntu1 --tty --interactive -v %SSH_CERT_DIR%:/root/.ssh-from-host-readonly/:ro -p 6080:80 ubuntu:16.04 /bin/bash
REM We have to copy over the .ssh-from-host folder over into something we own and
REM change the permisssions to 400 so the ssh-agent doesn't complain about "permissions too open"
set RUNNING_CHECKER_LOOP_COUNT=0
:running_check_loop
for /f "delims=" %%a in ('docker inspect ee-ubuntu1 --format="{{.State.Running}}"') do set IS_CONTAINER_RUNNING=%%a
if "%RUNNING_CHECKER_LOOP_COUNT%" == "5" (
echo "should exit loop"
goto exit_running_check_loop
)
if "%IS_CONTAINER_RUNNING%" == "true" (
echo "now running"
docker exec ee-ubuntu1 /bin/bash -c "cp -R ~/.ssh-from-host-readonly/ ~/.ssh-from-host && chmod -R 400 ~/.ssh-from-host"
) else (
echo looping%RUNNING_CHECKER_LOOP_COUNT%
set /A RUNNING_CHECKER_LOOP_COUNT=%RUNNING_CHECKER_LOOP_COUNT%+1
goto running_check_loop
)
:exit_running_check_loop
echo "Done trying to see if the container is running"
) else (
echo "Opening existing ee-ubuntu1 container"
docker start ee-ubuntu1
docker exec --tty --interactive ee-ubuntu1 /bin/bash
)