Docker as package manager for Linux

I first time tried Linux in 1995 and it was Red Hat Linux distribution version 2.1. Was quite a challenge to set it up to work with Intel 80486DX4. In 90’s installing something into Linux took some time to get used after Windows “anybody *.tar.gz + dependencies ? “

Red Hat was one of the 1st to come with integrated package management system RPM that suppose to solve dependencies. Once you start using more and more of the rpm installation limitation of the older version start to creep in called Dependency hell more exactly “rpm hall”. Debian was good alternative with DEB packages.

During the years I played with major Linux distributions Debian, Slackware and derivatives and Unix FreeBSD, OpenBSD and NetBSD, settling down with Gentoo for few years as documentation in the beginning of 2000’s was awesome. In my last 10 years + I am on Arch Linux as my primary desktop and my 1st and last time I reinstall my Arch on desktop was 5 years ago “I didn’t upgrade my desktop yet :)”

As you start experimenting with new software or never ending updates, your system will start get cluttered even with the best package managers “pacman :)”.

In Last 4 years I was using Docker as container deployment tool and I was thinking if docker can run my basic application for the shell ? Instead of installing new application I will build Docker images and will run as standard Linux application

It turns out you can comfortably run most of the Linux tools as docker container. Only problem you will need to maintain it yourself.

In this article will cover how run Amazon AWSCLI, Google Gcloud CLI, Terraform and Packer from docker image in Linux shell.

1st step is to create Dockerfile to build needed images.

Let’s start with AWSCLI Dockerfile.

Build docker image

docker build -t used_name/aws-cli .

NOTE: change user_name to you Docker Hub login.

Run container from newly created image.

docker run --rm -tiv $HOME/.aws:/root/.aws -v $(pwd):/aws used_name/aws-cli aws

To make it easy create an alias in ~/.bashrc file if you use bash

alias aws = "docker run --rm -tiv $HOME/.aws:/root/.aws -v $(pwd):/aws used_name/aws-cli aws"

Just to be aware of few potential issues.

Running command inside container is running as root and new file created on local system mapped to local file system Ex. $HOME/.aws during aws configuration command will be owned by root user. All will work at the, Work around is to create new used during container image build in Dockerfile and assign GUID and UID of your current Linux user and run command with created used inside docker image.

Let’s see the rest of the Dockerfiles and associated aliases.

Gcloud

Terraform

Packer

Aliases

alias gcloud='docker run -ti --rm  -v ~/:/root/ used_name/gcloud-cli gcloud'alias gsutil='docker run -ti --rm  -v ~/:/root/ used_name/gcloud-cli gsutil'alias packer='docker run -it --rm -v $(pwd):/app/ -w /app/ used_name/packer-cli packer'alias terraform='docker run -it --rm -v ${HOME}:/root -v $(pwd):/app/ -w /app/ used_name/terraform-cli terraform'

You can find all above and additional sources for Kubectl, Helm etc on my github account.

AWS-CLI

GCLOUD-BETA-CLI

GCLOUD-CLI

GCLOUD-KUBECTL-CLI

HELM-CLI

KUBECTL-CLI

PACKER-CLI

TERRAFORM-CLI

TFLINT-CLI

CONFIGURATION-FILES

Or pull docker images directly from Docker Hub

docker pull mudrii/aws-cli 
docker pull mudrii/gcloud-beta-cli
docker pull mudrii/gcloud-cli
docker pull mudrii/gkubectl-cli
docker pull mudrii/helm-cli
docker pull mudrii/kubectl-cli
docker pull mudrii/packer-cli
docker pull mudrii/terraform-cli
docker pull mudrii/tflint-cli

Can you run docker tools as al Alias in Windows 10 Power Shell ?

Yes you can, We need Docker for Windows to be installed.

Create new folder in your %HOME%\Documents\WindowsPowerShell\

Create new file in newly created folder Microsoft.PowerShell_profile.ps1

Add below entryes

#docker rm $(docker ps -a -q)
function Remove-StoppedContainers {
foreach ($id in & docker ps -a -q) {
& docker rm $id }
}
# docker inspect — format ‘{{ .NetworkSettings.Networks.nat.IPAddress }}’ <id>
function Get-ContainerIPAddress {
param (
[string] $id
)
& docker inspect — format ‘{{ .NetworkSettings.Networks.nat.IPAddress }}’ $id
}
#docker run gcloud
function Docker-Run-Gcloud {
docker run -ti — rm -v ~./.kube:/root/.kube -v ~./.config:/root/.config mudrii/gcloud-cli gcloud $args
}
#docker run terraform
function Docker-Run-Terraform {
docker run -ti — rm mudrii/terraform-cli $args
}
#docker run packer
function Docker-Run-Packer {
docker run -ti — rm mudrii/packer-cli $args
}
#docker run packer
function Docker-Run-Azure {
docker run -v ${HOME}:/root -it — rm azuresdk/azure-cli-python az $args
}
New-Alias drm Remove-StoppedContainers
New-Alias dip Get-ContainerIPAddress
New-Alias gcloud Docker-Run-Gcloud
New-Alias terraform Docker-Run-Terraform
New-Alias packer Docker-Run-Packer
New-Alias az Docker-Run-Azure

Leading Dev and DevOps/SRE teams