Skip to content

Instantly share code, notes, and snippets.

@mtotowamkwe
Created December 27, 2020 04:43
Show Gist options
  • Save mtotowamkwe/28ed9ab227f7d4678d6024d105977f6c to your computer and use it in GitHub Desktop.
Save mtotowamkwe/28ed9ab227f7d4678d6024d105977f6c to your computer and use it in GitHub Desktop.
How to build an Alpine Linux docker image with an instance of SQLite installed using a Dockerfile.

Building docker images with Dockerfiles.

To build an alpine linux docker image with sqlite.

  • Create a directory.
  • In the directory above create a Dockerfile.
  • Add the desired commands in the Dockerfile.

Following are the commands in the Dockerfile.

FROM alpine:3.12

RUN apk update && apk upgrade

RUN apk add --no-cache sqlite~=3.32.1-r0

Pull in the alpine linux image specifically version 3.12 then update and upgrade apk (a package manager for the Alpine distro) it's used to install additional software.

Lastly use apk to install sqlite note the semver tilde ranges i.e ~= which means the only versions of sqlite we want installed are equal to or greater than 3.32.1-r0 and less than 3.4.0

Finally build an image with the following command.

docker build -t your_new_image_name /path/to/the/Dockerfile

e.g. my Dockerfile is in the directory foo hence after I cd into foo I run the following command.

docker build -t my_alpine_linux_with_sqlite .

Then list your docker images with the command:-

docker images

You should see your_new_image_name among the list.

Then you can run a container off of your new image and sh into it (i.e. get into the container's shell) with

docker container run -ti your_new_image_name /bin/sh

In my case I ran

docker container run -ti my_alpine_linux_with_sqlite /bin/sh

Finally confirm sqlite is indeed installed by typing

sqlite3

and pressing enter. You'll see a sqlite prompt i.e.

sqlite>

And that is it congratulations you have installed sqlite.

Press Ctrl + D to quit sqlite then exit to exit your container's shell (in this case sh) and return back to your regular terminal (i.e. the host machine's shell).

@suriya786
Copy link

Thank you for the post. It was very helpful for me to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment