Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Init Layer in Docker

Tags:

docker

storage

Why is there a containerID-init layer created when a container is created from an image in Docker? Couldn't the new container have as parent the image?

like image 287
user2424276 Avatar asked Nov 13 '15 16:11

user2424276


People also ask

What does init do in Docker?

The docker app init command is used to initialize a new Docker application project. If you run it on its own, it initializes a new empty project. If you point it to an existing docker-compose. yml file, it initializes a new project based on the Compose file.

How do I add a layer in Docker?

A Docker image consists of several layers. Each layer corresponds to certain instructions in your Dockerfile . The following instructions create a layer: RUN , COPY , ADD . The other instructions will create intermediate layers and do not influence the size of your image.

Which Docker command create layers?

The COPY command adds some files from your Docker client's current directory. The first RUN command builds your application using the make command, and writes the result to a new layer. The second RUN command removes a cache directory, and writes the result to a new layer.


2 Answers

Each containers has two layers, one (called the init layer), which is based on an image layer and a child of that which contains the actual container content. The init layer contains a few files that must always exist in Docker containers (e.g. /.dockerinit). Supported Filesystems

The containerID-init layer is the init layer of a container which is based on an image. It add some file into current container,include:

    "/dev/pts":         "dir",
    "/dev/shm":         "dir",
    "/proc":            "dir",
    "/sys":             "dir",
    "/.dockerenv":      "file",
    "/etc/resolv.conf": "file",
    "/etc/hosts":       "file",
    "/etc/hostname":    "file",
    "/dev/console":     "file",
    "/etc/mtab":        "/proc/mounts",

code link

like image 166
wow qing Avatar answered Nov 01 '22 19:11

wow qing


<container>-init layer exists to create certain must exist files/directories(usually as mountpoints), so that docker can bind mount to these mountpoints without worrying they don't exist.

NOTE: init layer is RO(READONLY), can not by modified.

These mountpoints are usually empty, and the following explains their purpose:

  • /proc: in-memory data about processes and system
  • sys: in-memory system file system
  • /etc/hostname: container hostname file, each container will have their own hostname, and bind mount to this file
  • /etc/hosts: hosts file, ip and name mapping
  • /etc/resolv.conf: DNS-related resolve conf file
  • ......
like image 38
cizixs Avatar answered Nov 01 '22 18:11

cizixs