DEV Community

Pranava S Balugari
Pranava S Balugari

Posted on

interactively build a docker image

Let's take a close look at how to interactively build a docker image from base ubuntu image. We will use docker commands to create our custom image.

  • Interactively launch BASH shell under Ubuntu Base image, Update apt-get, install figlet and its dependencies using apt-get, and then save the image.

e.g.

Figlet software + Ubuntu base image -> New Image named figlet

Prerequisites:

Ensure the Docker engine is installed on your machine

Fetch the base image and connect to the container.

docker run -it ubuntu
Enter fullscreen mode Exit fullscreen mode

Next, Update apt-get update and its dependencies (with in the docker container)

apt-get update
Enter fullscreen mode Exit fullscreen mode

Install figlet software and its dependencies.

apt-get install figlet
Enter fullscreen mode Exit fullscreen mode

Verify if the software is installed correctly on the container.

figlet DEV.TO
Enter fullscreen mode Exit fullscreen mode

Alt Text

If your output matches the above image, exit the container (Ensure you copy the container id)

Now run docker commit command with the container id saved in the previous step.

// Works even if you mention initial chars of container id
docker commit cbe1bc 
Enter fullscreen mode Exit fullscreen mode

Now look at all the images

docker images

undefined              undefined              cbe1bc519023        39 hours ago        98MB
ubuntu              latest              4e2eef94cd6b        13 days ago         73.9MB

Enter fullscreen mode Exit fullscreen mode

Rename the image created with a readable name

docker tag cbe1bc519023 figlet
Enter fullscreen mode Exit fullscreen mode

Now look at all the images again

docker images

figlet              latest              cbe1bc519023        39 hours ago        98MB
ubuntu              latest              4e2eef94cd6b        13 days ago         73.9MB

Enter fullscreen mode Exit fullscreen mode

That is all :) Our custom image is ready to be pushed to docker hub and used by the community.

Note: Didn't cover the docker push and pull commands for the custom image created. That's for another day :)

...

Top comments (0)