User Tools

Site Tools


docker:images:create_an_image

Docker - Images - Create an image

Dockerfile
FROM ubuntu
 
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get autoremove -y && \
    apt-get install -y curl && \
    apt-get install -y most && \
    apt-get install -y htop && \
    apt-get install -y rar && \
    apt-get install -y p7zip && \
    apt-get install -y p7zip-full && \
    apt-get install -y p7zip-rar && \
    apt-get install -y unrar && \
    apt-get install -y mlocate

Build

docker build --tag test .

returns:

Sending build context to Docker daemon  3.072kB
Step 1/2 : FROM ubuntu
 ---> fb52e22af1b0
Step 2/2 : RUN apt-get update &&     apt-get upgrade -y &&     apt-get autoremove -y &&     apt-get install -y curl &&     apt-get install -y most &&     apt-get install -y htop &&     apt-get install -y rar &&     apt-get install -y p7zip &&     apt-get install -y p7zip-full &&     apt-get install -y p7zip-rar &&     apt-get install -y unrar &&     apt-get install -y mlocate
 ---> Running in 8f92220cd0c8
Get:1 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:8 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:9 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1071 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1537 kB]
Get:11 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [590 kB]
Get:12 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [33.3 kB]
Get:13 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [2668 B]
Get:14 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [6310 B]
Get:15 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [30.1 kB]
Get:16 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [1092 kB]
Get:17 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [791 kB]
Get:18 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [543 kB]
Fetched 19.1 MB in 1s (14.9 MB/s)
...

Test

Enter into the shell of the running

docker run -ti test

returns:

root@038e5ac922e4:/# 

NOTE: This indicates that the shell is working.

Try to run htop.


MOVE BELOW INTO SEPARATE LOCATION

Install Debian Base Packages

It’s fairly simple to install Debian’s base packages on your current machine and it doesn’t matter if you’re currently not on a Debian host system.

There’s a tool called debootstrap which does all the work for you.

You can download it via your package manager.

sudo apt install debootstrap

As soon as the utility is available on your system you just need to tell it the suite, target and the mirror so basically, in that order, the name of the Debian version, the directory where to install the packages and the URL from which the packages are downloaded.

Essentially the mirror is optional but we’ll specify it anyway here.

mkdir wheezy
sudo debootstrap wheezy ./wheezy http://http.debian.net/debian/

This step can take a moment depending on your internet connection.

You may have noticed that debootstrap requires root privileges to create a file system that belongs root.

Amongst the required suite and target Debian’s bootstrap utility also accepts options from which some are listed below.

SYNOPSIS
     debootstrap [OPTION...]  SUITE TARGET [MIRROR [SCRIPT]]
 
OPTIONS
     --include=alpha,beta
            Comma  separated  list  of  packages  which will be added to download and
            extract lists.
 
     --exclude=alpha,beta
            Comma separated list of packages which will be removed from download and
            extract lists. WARNING: you can and probably will exclude essential
            packages, be careful using this option.
 
     --variant=minbase|buildd|fakechroot|scratchbox
            Name of the bootstrap script variant to use. Currently, the variants
            supported are  minbase,  which  only  includes  essential  packages and
            apt; buildd, which installs the build-essential packages into TARGET;
            and fakechroot, which installs the packages without root privileges.
            Finally there is variant scratchbox, which is for creating targets for
            scratchbox usage. The default, with no --variant=X argument, is to create
            a base Debian installation in TARGET.
 
     --make-tarball=FILE
            Instead  of  bootstrapping,  make  a  tarball (written to FILE) of the
            downloaded packages.  The resulting tarball may be passed to a later
            --unpack-tarball.

Assuming you want to install additional packages such as zsh or git you can do so by specifying them with the --include option.


Create the tarball

Docker supports both non-compressed but also compressed images so a .tar, .tar.gz, .tgz, .bzip, .tar.xz or .txz image will be totally fine. Here we create a non-compressed tarball. In a subsequent step we’ll fix the tarball’s owner so that further work with docker can be done by non-root users.

sudo tar -C wheezy -cf wheezy.tar .
sudo chown you:you wheezy.tar

According to debootstrap’s documentation one should be able to use its option –make-tarball to create the tarball during the bootstrap process by executing:

debootstrap --make-tarball=wheezy.tar wheezy ./wheezy http://http.debian.net/debian/

but when doing so the image is some sort of corrupt and incomplete.

To share your image with the community you could upload the image and make it available for other docker users.

docker/images/create_an_image.txt · Last modified: 2021/09/24 21:53 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki