tutorials|March 03, 2021|1 min read

How to Install packages from command line and Dockerfile with Chocolatey

TL;DR

Use Chocolatey package manager on Windows to install tools like Git and osquery from the command line or within a Dockerfile.

How to Install packages from command line and Dockerfile with Chocolatey

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;

Related Posts

Dockerfile for building Python 3.9.2 and Openssl for FIPS

Dockerfile for building Python 3.9.2 and Openssl for FIPS

Introduction In previous posts, we saw how to build FIPS enabled Openssl, and…

How to get Youtube Video Thumbnail Images

How to get Youtube Video Thumbnail Images

If your youtube video looks like:https://www.youtube.com/watch?v=g0kFl7sBdDQ…

Lets-Encrypt SSL Certificate Useful Commands

Lets-Encrypt SSL Certificate Useful Commands

You might need to put sudo before above command. The command will show details…

Jenkinsfile - How to Create UI Form Text fields, Drop-down and Run for Different Conditions

Jenkinsfile - How to Create UI Form Text fields, Drop-down and Run for Different Conditions

Introduction I had to write a CICD system for one of our project. I had to…

How to automate create Function App with Blob Trigger and Sendgrid Notification through Azure Arm Template and deploy

How to automate create Function App with Blob Trigger and Sendgrid Notification through Azure Arm Template and deploy

In previous post (Trigger Email on Blob Trigger), we saw how we can create such…

Microsoft Azure Just-In-Time access control

Microsoft Azure Just-In-Time access control

According to Microsoft, Therefore, they recently posted about a feature in beta…

Latest Posts

REST API Design: Pagination, Versioning, and Best Practices

REST API Design: Pagination, Versioning, and Best Practices

Every time two systems need to talk, someone has to design the contract between…

Efficient Data Modelling: A Practical Guide for Production Systems

Efficient Data Modelling: A Practical Guide for Production Systems

Most engineers learn data modelling backwards. They draw an ER diagram…

Deep Dive on Caching: From Browser to Database

Deep Dive on Caching: From Browser to Database

“There are only two hard things in Computer Science: cache invalidation and…

System Design Patterns for Real-Time Updates at High Traffic

System Design Patterns for Real-Time Updates at High Traffic

The previous articles in this series covered scaling reads and scaling writes…

System Design Patterns for Scaling Writes

System Design Patterns for Scaling Writes

In the companion article on scaling reads, we covered caching, replicas, and…

System Design Patterns for Managing Long-Running Tasks

System Design Patterns for Managing Long-Running Tasks

Introduction Some operations simply can’t finish in the time a user is willing…