Skip to content

Instantly share code, notes, and snippets.

@BernCarney
Created October 15, 2017 05:19
Show Gist options
  • Save BernCarney/c016829743864cb0ca7178beb86d4d7f to your computer and use it in GitHub Desktop.
Save BernCarney/c016829743864cb0ca7178beb86d4d7f to your computer and use it in GitHub Desktop.
Powershell script to start, stop, and restart my jekyll dev container (and clear unsused containers)
#
# Script to start, stop, restart Jekyll Dev Environment container
#
# Set default parameter set
[cmdletbinding(DefaultParameterSetName='container')]
# Intialize parameters
param (
[Parameter(Mandatory = $true)]
[string]$exec,
[Parameter(ParameterSetName='container')]
[string]$name = 'jekyll_site_dev',
[string]$cID = $(docker ps -qf "name=$name")
)
# Run execute command
if ($exec -ieq 'start') { # Start
# Check that container is running
if($cID){
Write-Output "The dev container $name is already running with ID: $cID";
}
else {
Write-Output "Starting dev container $name...";
docker run --name $name -v D:/Documents/GitHub/BC-v2-Dev:/usr/src/app -e JEKYLL_GITHUB_TOKEN=7463cbd38876c56449328d0816f501d4b6980c4c7 -p "4000:4000" starefossen/github-pages;
}
} elseif ($exec -ieq 'stop') { # Stop
# Check that container is running
if($cID){
Write-Output "Stopping the dev container $name with ID: $cID";
docker container stop $cID;
docker ps -aq --no-trunc | %{docker rm $_};
}
else {
Write-Output "The dev container $name doesn't exist. Here are the current running containers:";
docker container ls;
}
} elseif ($exec -ieq 'restart') { # Restart
# Check that container is running otherwise just start it
if($cID){
Write-Output "Restarting the dev container $name with ID: $cID";
docker container restart $cID;
}
else {
$confirmation = Read-Host "That dev container doesn't exist. Would you like to start it? [y/n]"
if($confirmation -eq "y") {
docker run --name $name -v D:/Documents/GitHub/BC-v2-Dev:/usr/src/app -e JEKYLL_GITHUB_TOKEN=7463cbd38876c56449328d0816f501d4b6980c4c7 -p "4000:4000" starefossen/github-pages;
}
else {exit}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment