• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

How to create Ubuntu docker base image

October 9, 2018 by Sharad Chhetri

Have you just started working on docker containers? You may have also thought about how to create docker base image of the Operating System. In this post, we will learn to create Ubuntu docker base image.

Note: This method is applicable to create docker base image of all Ubuntu version. You can find Ubuntu release code name from here – https://wiki.ubuntu.com/Releases .

Goal

Create Ubuntu 18.04 LTS docker base image.

Prereqs

Debootstrap: We will use the deboostrap script to create the docker base image. To know more about debootstrap visit https://wiki.debian.org/Debootstrap .
Ubuntu Release Code Name: To create docker image we need ‘Ubuntu release code name’ for eg. “Bionic Beaver” or “Xenial Xerus”.

About our system

We are using Ubuntu 16.04 LTS Desktop but particular Operating System is not restrictive for creating docker base image. You can create Ubuntu docker image from other Linux system also but your system should have debootstrap script.

Steps to create Ubuntu docker base image

We are using our Ubuntu 16.04 LTS Desktop for creating base image.Hence,all commands are for debian/ubuntu system.

  1. Login as root or superuser
  2. Either login as root or become superuser by using command sudo su

  3. Create directory for docker image workshop
  4. Create directory for docker base image work and change to after creating it.

    mkdir -p /opt/docker_base_images
    
    cd /opt/docker_base_images
    
  5. Install debootstrap
  6. apt install debootstrap
    

    Output from our system

    root@sharadchhetri:/opt/docker_base_images# apt install debootstrap
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following NEW packages will be installed:
      debootstrap
    0 upgraded, 1 newly installed, 0 to remove and 35 not upgraded.
    Need to get 37.2 kB of archives.
    After this operation, 262 kB of additional disk space will be used.
    Get:1 http://in.archive.ubuntu.com/ubuntu xenial-updates/main amd64 debootstrap all 1.0.78+nmu1ubuntu1.6 [37.2 kB]
    Fetched 37.2 kB in 0s (60.1 kB/s)      
    Selecting previously unselected package debootstrap.
    (Reading database ... 380627 files and directories currently installed.)
    Preparing to unpack .../debootstrap_1.0.78+nmu1ubuntu1.6_all.deb ...
    Unpacking debootstrap (1.0.78+nmu1ubuntu1.6) ...
    Processing triggers for man-db (2.7.5-1) ...
    Setting up debootstrap (1.0.78+nmu1ubuntu1.6) ...
    root@sharadchhetri:/opt/docker_base_images#
    
  7. Run debootstrap
  8. Here,we are creating Ubuntu 18.04 LTS docker base image. For this, we will use the Ubuntu release code name that is ‘Bionic’. Command will take some time to finish.

    After command get completed, you will see the directory relevant to Ubuntu code name you used.In our case directory called ‘bionic’ is created.

    debootstrap bionic bionic > /dev/null
    

    Output from our system

    root@sharadchhetri:/opt/docker_base_images# debootstrap bionic bionic > /dev/null
     
    root@sharadchhetri:/opt/docker_base_images# 
    root@sharadchhetri:/opt/docker_base_images# ls -l
    total 4
    drwxr-xr-x 21 root root 4096 Oct  8 23:22 bionic
    root@sharadchhetri:/opt/docker_base_images# 
    
  9. Explore the newly created docker image directory
  10. Let’s explore what you got from debootstrap command. We are listing the files/directories in ‘bionic’ directory.

    In given below you can find the lsb_release output, showing the release details.

    Output from our system

    root@sharadchhetri:/opt/docker_base_images# ls bionic/
    bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
    root@sharadchhetri:/opt/docker_base_images# cat bionic/
    bin/   dev/   home/  lib64/ mnt/   proc/  run/   srv/   tmp/   var/   
    boot/  etc/   lib/   media/ opt/   root/  sbin/  sys/   usr/   
    root@sharadchhetri:/opt/docker_base_images# cat bionic/etc/l
    ld.so.cache     ld.so.conf.d/   libaudit.conf   locale.gen      logcheck/       logrotate.conf  lsb-release
    ld.so.conf      legal           locale.alias    localtime       login.defs      logrotate.d/    
    root@sharadchhetri:/opt/docker_base_images# cat bionic/etc/lsb-release 
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=18.04
    DISTRIB_CODENAME=bionic
    DISTRIB_DESCRIPTION="Ubuntu 18.04 LTS"
    root@sharadchhetri:/opt/docker_base_images#
    
  11. Docker import
  12. Now import the docker image in local system.

    sudo tar -C bionic -c . | docker import - bionic
    

    Output from our system

    root@sharadchhetri:/opt/docker_base_images# sudo tar -C bionic -c . | docker import - bionic
    sudo: unable to resolve host sharadchhetri
    sha256:48660241bce0fc8350e07f2ea84cbdc09e2027f3fc6cde21c2a6f8b7ee039967
    root@sharadchhetri:/opt/docker_base_images# 
    
  13. List docker images
  14. Now list docker images, you can easily find your freshly imported docker image.

    docker images
    

    Output from our system

    root@sharadchhetri:/opt/docker_base_images# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    bionic              latest              474342d581ce        9 seconds ago       289MB
    root@sharadchhetri:/opt/docker_base_images#
    
  15. Verify the new docker image
  16. Run this command to verify the Ubuntu docker image release version.

    docker run bionic cat /etc/lsb-release
    

    Output from our system

    root@sharadchhetri:/opt/docker_base_images# docker run bionic cat /etc/lsb-release
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=18.04
    DISTRIB_CODENAME=bionic
    DISTRIB_DESCRIPTION="Ubuntu 18.04 LTS"
    root@sharadchhetri:/opt/docker_base_images# 
    

    In given below Steps, we will push the image in Docker Hub.It is your choice if you want to share your docker image in internet .

  17. Login to docker hub
  18. Now login to Docker Hub.Always remember, you must have registered login id in https://hub.docker.com for this step. We already have our docker hub login.

    Run the given below command.

    docker login
    

    Output from our system
    Use your username of docker hub.

    root@sharadchhetri:/opt/docker_base_images# docker login
    Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
    Username: sharadchhetri
    Password: 
    WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
    Configure a credential helper to remove this warning. See
    https://docs.docker.com/engine/reference/commandline/login/#credentials-store
    
    Login Succeeded
    root@sharadchhetri:/opt/docker_base_images#
    
  19. Push image to Docker Hub
  20. Now push the newly created image to Docker Hub. Here, first we will tag the image and the push to Docker Hub.
    Use your Docker Hub username instead of ‘sharadchhetri’ in given below command.

    docker tag bionic sharadchhetri/bionic:latest
    
    docker push sharadchhetri/bionic:latest
    

    Output from our system

    root@sharadchhetri:/opt/docker_base_images# docker tag bionic sharadchhetri/bionic:latest
    
    root@sharadchhetri:/opt/docker_base_images# docker images 
    REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
    sharadchhetri/bionic   latest              474342d581ce        27 minutes ago      289MB
    bionic                 latest              474342d581ce        27 minutes ago      289MB
    root@sharadchhetri:/opt/docker_base_images#
    root@sharadchhetri:/opt/docker_base_images# docker push sharadchhetri/bionic:latest
    The push refers to repository [docker.io/sharadchhetri/bionic]
    cd4e432e52ec: Pushed 
    latest: digest: sha256:e9cf9ce4d13b2dbcd6c4ed038c0d7ae1922a8d458dac1b1bfe10f564b51efd6e size: 529
    root@sharadchhetri:/opt/docker_base_images# 
    
  21. Check your new image in Docker Hub
  22. Login to Docker Hub. You will see your freshly created image there. You can use this image for creating docker containers directly pulling from your own Docker Hub repository.

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. create iso image of directory in linux
  2. WordPress error “Unable to create new image”
  3. How to install Docker on Ubuntu
  4. Yum Error database disk image is malformed
  5. Jpeg Image Optimization / Compress on Linux
  6. Convert website page to pdf and image
  7. Install Docker on CentOS 7
  8. How to install Docker on CentOS 8
  9. Install Vagrant on Ubuntu and create first VM
  10. How to create own Git Server with Gitolite and Gitweb in Ubuntu

Filed Under: Containers Tagged With: docker, ubuntu

Reader Interactions

Comments

  1. Rodney Jackson says

    October 10, 2018 at 12:30 am

    Hi, I am using ubuntu 16.04lts and have done so for about 3 years now.
    I am curious about the docker, what is its use.? It seems to favour the 18.04lts program, which I have a small problem with. I downloaded 18.04 and horror, it is no longer Debian based, I still have problems using 16.04, I follow to the letter trying to E.G. Install Pretty Good Solitaire, which relies on “Wine”. I have a printed copy of how to do this, but as always, it gets to a point where I am asked to open something, but that something does not exist on my machine, as you can imagine it is frustrating. If I went to 18.04 I would be back at square one and have to re-learn everything again. Being a senior person (75) it is hard to retain knowledge. Perhaps some kind soul out there will open my eyes and explain how simple things are to change, (step by step).
    Thanks for reading my groans….

    Rod.

    • Sharad Chhetri says

      October 10, 2018 at 4:52 pm

      Hello Sir,

      Thank you for commenting! Docker is a program for containerization. In simple term,build the app and ship it to containers.
      I am not big fan of Wine but I also understand your interest. I will try to install solitaire. I quickly searched found this result https://askubuntu.com/questions/675260/is-there-an-ubuntu-solitaire-that-works-like-the-windows-7-game .

      Regards
      Sharad

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

sed: -e expression #1, char 24: Invalid range end

Terminal Recording with script and scriptreplay command

Convert new line to space by using sed command

The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form

How to convert float to integer number

Print double hyphen sign simultaneously in post of Octopress

How to find when Operating system was installed in linux CentOS and Red Hat

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy