Codementor Events

Creating a Docker Image

Published May 10, 2021

Often times we get a need to create our own docker images.

In this post, pur goal is to test gitleaks nside of a docker container.
Testing as in getting inside the docker container and running the gitleak command.

Not of the existing images can do this for us.

So, lets start by pulling this base image:

docker pull python:3.8-slim

Next login to the container:

docker pull python:3.8-slim

We will see a bash prompt. We are inside the container now.

Lets install the needed s/w for our testing. Run this from inside the container.

apt-get update
apt-get install wget
wget -c https://github.com/zricethezav/gitleaks/releases/download/v6.2.0/gitleaks-linux-amd64
mv gitleaks-linux-amd64 gitleaks
chmod 700 gitleaks

We are almost done with installing the needed s/w for our testing.
We need to capture the container id.
While you are still inside this container, open another terminal and get the container id of the running container.

**docker ps**
CONTAINER ID   IMAGE             COMMAND   CREATED          STATUS          PORTS     NAMES
**56c27dadeee5**   python:3.8-slim   "bash"    13 minutes ago   Up 13 minutes             competent_kalam

The container of interest is 56c27dadeee5 as noted in the above output.
Now exit from the container Run the following command to create an image.

docker commit 56c27dadeee5 python_3_8_slim_wget_git

The image we created is python_3_8_slim_wget_git.

We can now use the image and go about with our testing.

docker run -it  python_3_8_slim_wget_git bash

Discover and read more posts from Rajaram K
get started