How to Install packages from command line and Dockerfile with Chocolatey

March 03, 2021

Introduction

We will introduce a Package Manager for Windows: Chocolatey. In automations, it is necessary to install various tools, softwares from command line.

In this post, we will install git and osquery.

Install Chocolatey

Open powershell console.

RUN Set-ExecutionPolicy Bypass -Scope Process -Force; \
 [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls,Tls11,Tls12'; \
 iex ((New-Object System.Net.WebClient).DownloadString("https://chocolatey.org/install.ps1"));

Install a package (git)

Lets install git.

choco install git -y

Install specific version of a package

choco install osquery --version 3.4.0 -y;

Dockerfile

FROM microsoft/windowsservercore:ltsc2016

ENV CHOCO_URL=https://chocolatey.org/install.ps1
RUN Set-ExecutionPolicy Bypass -Scope Process -Force; \
 [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls,Tls11,Tls12'; \
 iex ((New-Object System.Net.WebClient).DownloadString("$env:CHOCO_URL"));

RUN choco install git -y;
RUN choco install osquery --version 3.4.0 -y;

Similar Posts

Latest Posts