fix(docs): fix cp and add step to include binaries in the $env:Path

This commit adds an extra (optional) step for the Windows
installation/set-up to include the containerd binaries in
the $env:Path so that later executions especially
for `ctr.exe` if needed, do not require to specify the full path.

It also further fixes the previous steps to be absolute and
also work with re-installations and upgrades.

Signed-off-by: Anthony Nandaa <profnandaa@gmail.com>
This commit is contained in:
Anthony Nandaa 2024-02-05 11:39:56 +03:00
parent f5e7fe0cb6
commit 9ef94fe528

View File

@ -110,8 +110,11 @@ To install containerd and its dependencies from the source, see [`BUILDING.md`](
From a PowerShell session run the following commands: From a PowerShell session run the following commands:
```PowerShell ```PowerShell
# If containerd previously installed run:
Stop-Service containerd
# Download and extract desired containerd Windows binaries # Download and extract desired containerd Windows binaries
$Version="1.6.4" $Version="1.7.13" # update to your preferred version
curl.exe -L https://github.com/containerd/containerd/releases/download/v$Version/containerd-$Version-windows-amd64.tar.gz -o containerd-windows-amd64.tar.gz curl.exe -L https://github.com/containerd/containerd/releases/download/v$Version/containerd-$Version-windows-amd64.tar.gz -o containerd-windows-amd64.tar.gz
tar.exe xvf .\containerd-windows-amd64.tar.gz tar.exe xvf .\containerd-windows-amd64.tar.gz
@ -120,16 +123,41 @@ Copy-Item -Path ".\bin" -Destination "$Env:ProgramFiles\containerd" -Recurse -Co
cd $Env:ProgramFiles\containerd\ cd $Env:ProgramFiles\containerd\
.\containerd.exe config default | Out-File config.toml -Encoding ascii .\containerd.exe config default | Out-File config.toml -Encoding ascii
# Copy
Copy-Item -Path .\bin\* -Destination (New-Item -Type Directory $Env:ProgramFiles\containerd -Force) -Recurse -Force
# add the binaries (containerd.exe, ctr.exe) in $env:Path
$Path = [Environment]::GetEnvironmentVariable("PATH", "Machine") + [IO.Path]::PathSeparator + "$Env:ProgramFiles\containerd"
[Environment]::SetEnvironmentVariable( "Path", $Path, "Machine")
# reload path, so you don't have to open a new PS terminal later if needed
$Env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
# configure
containerd.exe config default | Out-File $Env:ProgramFiles\containerd\config.toml -Encoding ascii
# Review the configuration. Depending on setup you may want to adjust: # Review the configuration. Depending on setup you may want to adjust:
# - the sandbox_image (Kubernetes pause image) # - the sandbox_image (Kubernetes pause image)
# - cni bin_dir and conf_dir locations # - cni bin_dir and conf_dir locations
Get-Content config.toml Get-Content $Env:ProgramFiles\containerd\config.toml
# Register and start service # Register and start service
.\containerd.exe --register-service containerd.exe --register-service
Start-Service containerd Start-Service containerd
``` ```
> **Tip for Running `containerd` Service on Windows:**
>
> `containerd` logs are not persisted when we start it as a service
using Windows Service Manager. [`nssm`](https://nssm.cc) can be used to
configure logs to go into a cyclic buffer:
> ```powershell
> nssm.exe install containerd
> nssm.exe set containerd AppStdout "\containerd.log"
> nssm.exe set containerd AppStderr "\containerd.err.log"
> nssm.exe start containerd
> # to stop:
> nssm.exe stop containerd
> ```
## Interacting with containerd via CLI ## Interacting with containerd via CLI
There are several command line interface (CLI) projects for interacting with containerd: There are several command line interface (CLI) projects for interacting with containerd: