Created
September 16, 2024 06:25
-
-
Save x-limitless-x/dcc14c368c5adebcf58dac93f0c0db95 to your computer and use it in GitHub Desktop.
This PowerShell script ensures Docker Desktop is running, pulls the latest Docker images, and starts the containers. It automates the process of updating and running Docker services efficiently.
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
# ======================================== | |
# Author: Blake Drumm (limitless) | |
# Created: September 16th, 2024 | |
# Description: This script checks if Docker Desktop is running, starts it if necessary, and then pulls the latest Docker images and starts the containers. | |
# ======================================== | |
# --------------------------------------------------------- | |
# Variables | |
# --------------------------------------------------------- | |
$PathToDockerCompose = 'C:\Users\Blake Drumm\OneDrive\Documents\Adams-Media-Server' | |
# --------------------------------------------------------- | |
$DockerProcess = Get-Process | Where-Object {$_.ProcessName -eq 'Docker Desktop'} | |
if (-NOT $DockerProcess) | |
{ | |
Write-Output "Starting Docker Desktop" | |
Start-Process -FilePath "C:\Program Files\Docker\Docker\Docker Desktop.exe" | |
Write-Host " - Waiting for application to start" -NoNewLine | |
# Sleep for 30 seconds, writing out each second | |
for ($i = 1; $i -le 30; $i++) { | |
Start-Sleep -Seconds 1 | |
Write-Host "." -NoNewLine | |
} | |
Write-Output " " | |
# Check if Docker Desktop has started | |
$DockerProcess = Get-Process | Where-Object {$_.ProcessName -eq 'Docker Desktop'} | |
if ($DockerProcess) { | |
Write-Output "Docker Desktop started successfully" | |
} else { | |
Write-Output "Failed to start Docker Desktop" | |
break | |
} | |
} | |
else | |
{ | |
Write-Output "Docker Desktop is already running" | |
} | |
Push-Location $PathToDockerCompose | |
Write-Output " " | |
Write-Output "==========================================================" | |
Write-Output "Pulling latest service images" | |
Write-Output "==========================================================" | |
docker compose pull | |
Write-Output " " | |
Write-Output "==========================================================" | |
Write-Output "Creating and starting docker containers" | |
Write-Output "==========================================================" | |
docker compose up -d | |
Pop-Location |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment