15

I'm new to Docker and I think having understood that Docker is a Software virtualization tool (by opposition to OS virtualization). I understand, by this image, that Docker provides a very blank environment with a given file structure and is executing on the kernel Host. What we need to do is to put our application and its dependencies (with no OS) to have a very light portable container of our app.

But it seems there is a dark side of Docker : each Dockerfile begins with a "FROM ".

I saw this and this but I'm not sure to understand. It sounds that Docker is near an kind of simplified OS virtualizer.

I was interesting in the advantage of images size. But if we have to install an OS on each image my "portable" application will be quite heavy quickly.

Is there really no way to use a "blank image" ?

Community
  • 1
  • 1
Richard
  • 391
  • 2
  • 3
  • 10
  • 1
    `FROM x` doesn't make a full copy of `x` on sane docker backends (because docker is pluggable, it's also possible to have less-sane backends... but if you use AUFS, this will work properly), but rather reuses the copy of `x` elsewhere -- think of it as copy-on-write. **NOT** using `FROM x` is what's inefficient/heavy, as it means that your image needs to contain its full dependency chain, as opposed to sharing that chain with everything else derived from the same parent. – Charles Duffy Jul 21 '14 at 19:41
  • check for this article "Create The Smallest Possible Docker Container" http://blog.xebia.com/2014/07/04/create-the-smallest-possible-docker-container/ it can be usefull – Mikl Nov 13 '14 at 18:00

3 Answers3

19

You can start with FROM scratch which is an empty filesystem.

Please see the section on Creating a Base Image if you'd like to spin up your own minimal root file system.

You might be surprised how many dependencies your application actually has on the root file system, and in the end, it is usually more efficient to use one of the standard root file systems in your FROM statement, as Charles Duffy commented above.

sudo
  • 906
  • 2
  • 14
  • 32
Andy
  • 35,844
  • 6
  • 43
  • 50
9

empty/Dockerfile

FROM scratch
WORKDIR /

build and check size

docker build empty/ -t empty
docker images | grep empty
mgttt
  • 351
  • 3
  • 4
  • It says "writing image sha256:47ccfa9dbc8fce746abe2416138bdb2c18d6ade5c7d3ba54ccfcab5bc587e2b3" and size is reported as 0B. Does that sound correct? echo -n '' | sha256sum is 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' though, so that image definitely is not the empty file. What's in there, what's the structure of a docker image and what is the hash computed over? – masterxilo Apr 30 '23 at 00:24
4

This may be a bit too late. But I just had a use case where I needed to create a bare bone container that I could launch as part of multi-container docker-compose and get into it afterwards via /bin/bash. Keep in mind, a docker container must run a service and the container will be in existence only for as long as the service is running. So, I created this container with just python in it. I copied a 2 line python script that just makes it sleep. Here's what I did. 1. Create the python script wait_service.py with the following code:

    import time
    time.sleep(1000)

2. Create the Dockerfile with just the following lines:

    FROM python:2.7
    RUN mkdir -p /test
    WORKDIR /test
    COPY wait_service.py /test/
    CMD python wait_service.py

3. Build and run the container. Using the container id, I could then get inside it. Please adjust the sleep time based on how long you want to keep this container.

Dean Sha
  • 837
  • 1
  • 10
  • 15