Creating Docker Base Images

by Anish


Posted on Monday September 30th 2019


Referefce 8gwifi.org

FROM scratch : The scratch image is mostly used for building base images, this image is the most minimal image in Docker doesn't contain any folders/files.

Here is the example of creating sample base images for your environment.

Centos7

The Dockerfile of creating Centos7 base Image. The centos-7.2.1511-docker.tar.xz contains all the files system files for Centos7.

FROM scratch
LABEL org.label-schema.schema-version="1.0" \
    org.label-schema.name="CentOS Base Image" \
    maintainer="https://0cloud0.com" \
    org.label-schema.vcs-description="centos7 Base Image-minimal" \
    org.label-schema.docker.cmd="docker run centos7" \
    org.label-schema.vendor="CentOS" \
    org.label-schema.license="GPLv2" \
    org.label-schema.build-date="20190801"
ADD centos-7.2.1511-docker.tar.xz /
CMD ["/bin/bash"]

Build the Image

$ docker build -t centos7base .
Sending build context to Docker daemon  41.64MB
Step 1/4 : FROM scratch
 ---> 
Step 2/4 : LABEL org.label-schema.schema-version "1.0" org.label-schema.name "CentOS Base Image" maintainer "https://0cloud0.com" org.label-schema.vcs-description "centos7 Base Image-minimal" org.label-schema.docker.cmd "docker run centos7" org.label-schema.vendor "CentOS" org.label-schema.license "GPLv2" org.label-schema.build-date "20190801"
 ---> Running in ba49592c00d7
 ---> b41063db123d
Removing intermediate container ba49592c00d7
Step 3/4 : ADD centos-7.2.1511-docker.tar.xz /
 ---> e37168ffbf32
Step 4/4 : CMD /bin/bash
 ---> Running in 6a717baa623a
 ---> 381e5df2768e
Removing intermediate container 6a717baa623a
Successfully built 381e5df2768e
Successfully tagged centos7base:latest

Run the Image and open the Interactive Terminal

$ docker run -it centos7base sh
sh-4.2# 

Check the Centos7 Base release version.

sh-4.2# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

Video Demo


Debian

The Dockerfile of creating Debian 10 base Image. The rootfs.tar.xz contains all the files system files for Debian 10.

FROM scratch
LABEL org.label-schema.schema-version="1.0" \
    org.label-schema.name="Debian Base Image" \
    maintainer="https://0cloud0.com Anish Nath" \
    org.label-schema.vcs-description="Debian 10 Base Image-minimal" \
    org.label-schema.docker.cmd="docker run -it debian sh" \
    org.label-schema.vendor="Debian" \
    org.label-schema.license="GPLv2" \
    org.label-schema.build-date="20190801"
ADD rootfs.tar.xz /
CMD ["/bin/bash"]

Build the Image

$ docker build -t debianbase .
Sending build context to Docker daemon  70.14kB
Step 1/4 : FROM scratch
 ---> 
Step 2/4 : LABEL org.label-schema.schema-version "1.0" org.label-schema.name "Debian Base Image" maintainer "https://0cloud0.com Anish Nath" org.label-schema.vcs-description "centos7 Base Image-minimal" org.label-schema.docker.cmd "docker run -it debian sh" org.label-schema.vendor "Debian" org.label-schema.license "GPLv2" org.label-schema.build-date "20190801"
 ---> Running in b26251a26114
 ---> 56ab96d932a9
Removing intermediate container b26251a26114
Step 3/4 : ADD rootfs.tar.xz /
 ---> 64fa174d654d
Step 4/4 : CMD /bin/bash
 ---> Running in 87a6abd6b93a
 ---> 9233dd6b47b6
Removing intermediate container 87a6abd6b93a
Successfully built 9233dd6b47b6
Successfully tagged debianbase:latest

Run the Image and open the Interactive Terminal

$ docker run -it debian sh 
# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Video Demo


Ubuntu 19.04

The Dockerfile of creating Ubuntu19.04 base Image. The ubuntu-base-19.04-base-amd64.tar.gz contains all the files system files for Ubuntu19.04.

FROM scratch
LABEL org.label-schema.schema-version="1.0" \
    org.label-schema.name="Ubuntu Base Image" \
    maintainer="https://0cloud0.com Anish Nath" \
    org.label-schema.vcs-description="ubuntu Base Image-minimal" \
    org.label-schema.docker.cmd="docker run -it ubuntu sh" \
    org.label-schema.vendor="ubuntu" \
    org.label-schema.license="GPLv2" \
    org.label-schema.build-date="20190801"
ADD ubuntu-base-19.04-base-amd64.tar.gz /
CMD ["/bin/bash"]

Build the Image

$ docker build -t ubuntu19.04base .
Sending build context to Docker daemon  28.99MB
Step 1/4 : FROM scratch
 ---> 
Step 2/4 : LABEL org.label-schema.schema-version "1.0" org.label-schema.name "Ubuntu Base Image" maintainer "https://leanpub.com/dockerfile Anish Nath" org.label-schema.vcs-description "ubuntu Base Image-minimal" org.label-schema.docker.cmd "docker run -it ubuntu sh" org.label-schema.vendor "ubuntu" org.label-schema.license "GPLv2" org.label-schema.build-date "20190801"
 ---> Running in 162d2059edb9
 ---> 5525d0accb3e
Removing intermediate container 162d2059edb9
Step 3/4 : ADD ubuntu-base-19.04-base-amd64.tar.gz /
 ---> aa40149e0c02
Step 4/4 : CMD /bin/bash
 ---> Running in aaceddab6dce
 ---> b1ddc781e8b2
Removing intermediate container aaceddab6dce
Successfully built b1ddc781e8b2
Successfully tagged ubuntu19.04base:latest

Run the Image and open the Interactive Terminal

$ docker run -it ubuntu19.04base sh 
# cat /etc/os-release
NAME="Ubuntu"
VERSION="19.04 (Disco Dingo)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 19.04"
VERSION_ID="19.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=disco
UBUNTU_CODENAME=disco
# exit

Now that you have a base image installed, you have many choices for what to do next.

Next Reading : Docker Private Repo Setup



Thanku for reading !!! Give a Share for Support


Your Support Matters!

Instead of directly asking for donations, I'm thrilled to offer you all nine of my books for just $9 on leanpub By grabbing this bundle you not only help cover my coffee, beer, and Amazon bills but also play a crucial role in advancing and refining this project. Your contribution is indispensable, and I'm genuinely grateful for your involvement in this journey!

Any private key value that you enter or we generate is not stored on this site, this tool is provided via an HTTPS URL to ensure that private keys cannot be stolen, for extra security run this software on your network, no cloud dependency



python Cryptography Topics
Topics
For Coffee/ Beer/ Amazon Bill and further development of the project Support by Purchasing, The Modern Cryptography CookBook for Just $9 Coupon Price

Kubernetes for DevOps

Hello Dockerfile

Cryptography for Python Developers

Cryptography for JavaScript Developers

Go lang ryptography for Developers