-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-mongodb.ps1
36 lines (34 loc) · 1.25 KB
/
run-mongodb.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$volumes = docker volume ls
$confVolumeExists = $volumes | Where-Object { $_ -like "*mongo-conf*" }
if (!$confVolumeExists)
{
docker volume create mongo-conf
}
$dataVolumeExists = $volumes | Where-Object { $_ -like "*mongo-data*" }
if (!$dataVolumeExists)
{
docker volume create mongo-data
}
$rootVolumeExists = $volumes | Where-Object { $_ -like "*mongo-root*" }
if (!$rootVolumeExists)
{
docker volume create mongo-root
}
$networks = docker network ls
$networkExists = $networks | Where-Object { $_ -like "*cs-network*" }
if(!$networkExists )
{
docker network create cs-network
}
docker run --name mongo-server --network=cs-network --volume=mongo-conf:/etc/mongo --volume=mongo-data:/data/db --volume=mongo-root:/run/secrets/mongo-root --volume=/data/configdb --volume=/data/db -p 27017:27017 --restart=always -d mongo:latest
$hostsFile = "$env:SystemRoot\System32\drivers\etc\hosts"
$hostname = "mongo-server"
$ipAddress = "127.0.0.1"
$existingEntry = Get-Content $hostsFile | Where-Object { $_ -like "*$hostname*" }
if ($existingEntry) {
Write-Host "Host entry for $hostname already exists."
} else {
$newEntry = "$ipAddress`t$hostname"
Add-Content -Path $hostsFile -Value $newEntry
Write-Host "Host entry for $hostname added successfully."
}