Example use case
Maybe you need a value in a Docker config.json
to be updated and persist, but the value resets whenever Docker is closed down.
Solution
Create a startup script
In any text editor or IDE, create a startup.ps1
file.
In the file, add the following (while replacing with the values relevant to you):
powershell -Command "(gc \\wsl$\Ubuntu-20.04\home\wilco\.docker\config.json) --replace 'oldvalue', 'newvalue' | sc \\wsl$\Ubuntu-20.04\home\wilco\.docker\config.json"
gc
: Get-Content (get the contents of a file)
sc
: Set-Content (write to a file)
Place this file in a convenient location, such as your user directory or C:\tools
.
Schedule a startup task
- Open the Task Scheduler (Windows key + start typing task, then select it)
- Hit Create Basic Task.. (under Task Scheduler Library)
- Give the task a name you will recognise later
- Hit Next
- Choose When I log on
- Hit Next
- Ensure Start a program is selected
- Hit Next
- For Program/script, enter PowerShell.exe
- For Add arguments, add -ExecutionPolicy Bypass C:\YOURSCRIPTLOCATION\startup.ps1
- Hit Next
- Hit Finish
-ExecutionPolicy Bypass
: you're allowing PowerShell to do anything in this script, nothing is blocked or warned about.
And there you go. Check the file has the old value, reboot, and you will find the file is now updated.