Tips & Tricks with Alpine + Docker

I'll be updating this post with new tips and tricks about Alpine + Docker as my personal list of useful commands and configurations.


Install and remove cache afterwards

Notice: This command it's only available from Alpine version 3.3

RUN apk --no-cache add curl  

That will install curl running first apk update and then rm -rf /var/cache/apk/*


Group dependencies (easy clean)

If installing like:

RUN apk add --virtual .build-dependencies curl make  

Will allow us to remove all dependencies with just one command

RUN apk del .build-dependencies  

If C libraries needed as glibc

I'll recommed you use instead of alpine base image directly this other image frol/docker-alpine-glibc that will install for us an unofficial glib library that will solve of problem


Manage users and groups

You could use shadow tool suite, atm it's on the testing repository so we'll need first to:

echo http://nl.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories  

And then we'll be able to install the package

apk --no-cache add shadow  

Shadow features

Default

By default we can find the following useful commands to be used:

delgroup ping # remove group ping  
addgroup -g 999 docker # create group docker with gid 999  
addgroup jenkins docker # add user jenkins to group docker  
groups jenkins # groups for user jenkins  
id -Gn docker # info about the users groups  
getent group docker # info about the group docker  

Note: this are just examples to illustrate the useage of those commands


Install a specific version of a package that it's not on the default repo

This is the way I like most because keeps things clean is it truth that I normally have to do this for just one package it I had more that one package I'll do it in a different way.

apk add 'postgresql>9.5' --update-cache --repository http://nl.alpinelinux.org/alpine/edge/main \

Notice: With more than one I problably define a repository like echo "@edge http://nl.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories and use it like apk add "postgresql@edge>9.4"


Run docker-compose on Alpine

Just to point out that we must be carfull because it will depend on the flavour we are using for docker-compose
will be linked to glibc instead musl so or we recompile docker-compose with musl or we add glibc in or alpine images.


Examples

The following are some of my base images build using Alpine

 Resources