The official Windows and Linux Docker images for Chocolatey CLI are now available on Docker Hub. Simply run docker pull chocolatey/choco
to download the latest image.
This is the first official Chocolatey CLI build that runs on Linux (via Mono), although unofficial builds have previously been created by a community member. There is more information about running on non-Windows systems on the Chocolatey documentation site.
The Windows Container Image
The chocolatey/choco:latest-windows
image for Windows containers is based on the servercore:ltsc2016
image, which has full support for the .NET Framework. Chocolatey, and Chocolatey Licensed Extension, are fully functional, and most packages will work, except packages that contain installers that require a GUI to run and other installers that are incompatible with running inside a container. In addition, Package Builder and Package Uploader GUI, that come with Chocolatey For Business, will not work for the same reasons.
The Linux Container Image
The chocolatey/choco:latest-linux
image for Linux containers is based on mono:6.12
, which itself is based on a Debian image.
Chocolatey CLI on non-Windows platforms has a specific focus of creation and maintenance of packages. See the docs for more information.
At the moment the Chocolatey Licensed Extension does not work in a Linux container and may actually result in a broken Chocolatey CLI install if you attempt to install it. We would recommend that licensed customers do not license Chocolatey on the Linux container or, if that is not an option, use the Windows container instead.
Why Docker Containers?
Containers are useful for the same reasons that virtual machines are useful; being able to create an isolated environment in which to run software. With Docker containers it is fast and easy to download and run a prebuilt environment.
Using a Docker container, packages:
- Can be tested in a repeatable, isolated environment before deployment to a repository.
- With Chocolatey For Business, the testing could be preceded by automatic internalization of the package.
- If your packages are maintained in a CI system, the Chocolatey Docker container could be an easy environment in which to do the update.
Why Both A Linux And Windows container?
There are two big reasons that I wanted to create a Linux based image, as well as a Windows one.
The first is that the Linux based images have a number of advantages over Windows images. They are much smaller, so less bandwidth and disk space are used, they are quick to start up and they can be run with minimal memory requirements. More operating systems support Linux containers, as they can be run on both Windows and MacOS systems, which also translates to better support for them in external tools.
The second reason is selfish. Chocolatey CLI can now run on all of my machines! Instead of having a Windows server for maintenance of internal packages, I can now do this right next to my internal Sonatype Nexus repository instance.
How To Use The Docker Images
The Basics
First up, you need Docker installed on your system. If you’re running Windows, that’s easy because you are running Chocolatey, right? Just run choco install docker-desktop -y
. For non-Windows systems, consult the Get Docker documentation.
Once Docker is installed, you can pull down the image with the ‘latest’ tag by running docker pull chocolatey/choco:latest
. See the tags list for the full list of available tags.
Now you can create a container from the image with docker run --rm -it chocolatey/choco <command>
To explore the container, use a command line shell as the command, e.g. cmd.exe
for Windows and bash
for Linux. For example, docker run --rm -it chocolatey/choco cmd.exe
.
Host Files Access
Now that you can run a container, there is a good chance you want to access files on the host, from inside the container. You may want to pack and push a package for example. This can done with the --volume
argument, for example docker run --rm -it --volume=<path on host>:<path in container> chocolatey/choco <command>
For more information on the --volume
argument, see the Docker documentation.
Using A Container For Automatic Package (AU)
You can build on and modify Docker images depending on your needs. For example, if you want update packages with AU then the Windows image Dockerfile below could be used to build the image with it.
FROM chocolatey/choco:latest-windows
RUN choco install au --yes
CMD PowerShell.exe
AU also runs on Linux and the Dockerfile below can be used to build an image with it installed.
FROM chocolatey/choco:latest-linux
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y wget apt-utils gnupg apt-transport-https
RUN wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb && \
apt-get install ./packages-microsoft-prod.deb -y && \
apt-get update && \
apt-get install -y powershell
RUN pwsh -Command Install-Module AU -F
WORKDIR /root
CMD pwsh
Once you have the Dockerfile you can build the image by running docker build -t <image name> .
from the same directory as the Dockerfile. Then you can run the newly created image with docker run --rm -it <image name> <command>
.
I’m really excited about the ability to run Chocolatey across both Windows and Linux and I hope this blog post outlines how you can use the official Chocolatey Docker images.
Popular Tags
- #news 72 Number of post with tag news
- #press release 57 Number of post with tag press release
- #chocolatey for business 46 Number of post with tag chocolatey for business
- #packaging 21 Number of post with tag packaging
- #open source 17 Number of post with tag open source
- #community 15 Number of post with tag community
- #tutorial 14 Number of post with tag tutorial
- #12 days of Chocolatey 2023 12 Number of post with tag 12 days of Chocolatey 2023
- #chocolatey community repository 12 Number of post with tag chocolatey community repository
- #podcast 12 Number of post with tag podcast