Advertisement
About80Ninjas

Setup Docker Volume

May 8th, 2024
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This script will create docker volumes in the specified path and inspect them after creation
  2.  
  3. # Define an array of volume names
  4. $Volumes = @("jenkins", "webapps", "gitea", "giteasql")
  5.  
  6. # Define the path where the volumes will be created
  7. $PathToVolumes = "C:\Dev\docker\volumes\"
  8.  
  9. # Define the docker command to create volumes
  10. # The --opt type=none option specifies a non-docker managed volume
  11. # The --opt o=bind option binds the volume to a directory on the host machine
  12. # The --opt device=$PathToVolumes option specifies the directory on the host machine where the volume will be created
  13. $dockercmd = "docker volume create --opt type=none --opt o=bind --opt device=$PathToVolumes"
  14.  
  15. # Loop through each volume name in the array
  16. $Volumes | ForEach-Object {  
  17.  
  18.     # Create a full command by concatenating the docker command with the volume name
  19.     $fullcmd = $dockercmd + $_ + ' ' + $_
  20.  
  21.     # Execute the full command using Invoke-Expression
  22.     # This will create the volume with the specified name and bind it to the specified directory on the host machine
  23.     Invoke-Expression $fullcmd
  24.  
  25.     # Execute the docker command to inspect the volume with the specified name
  26.     # This will display information about the volume, such as its driver, name, and mount point
  27.     Invoke-Expression "docker volume inspect $($_)"
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement