Skip to content

Commit c5dd428

Browse files
authored
Merge pull request #10 from grycap/manpages
man pages and updating documentation
2 parents 559825c + 5a58936 commit c5dd428

File tree

12 files changed

+972
-73
lines changed

12 files changed

+972
-73
lines changed

README.md

Lines changed: 34 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1-
# MiniDock - minimization of Docker containers
1+
# minicon - minimization containers
22

3-
When you run Docker containers, you usually run a system that has a whole Operating System and your specific application. The result is that the footprint of the container is bigger than needed.
3+
When you run containers (e.g. in Docker), you usually run a system that has a whole Operating System, documentation, extra packages, etc. and your specific application. The result is that the footprint of the container is bigger than needed.
44

5-
**minidock** aims at reducing the footprint of the Docker containers, by just including in the container those files that are needed. That means that the other files in the original container are removed.
5+
**minicon** aims at reducing the footprint of the Docker containers, by just including in the container those files that are needed. That means that the other files in the original container are removed.
66

7-
The purpose of **minidock** is better understood with the use cases explained in depth in the section "[Examples](#4-examples)": the size of an Apache server is reduced from 216MB. to 50.4MB., and the size of a Perl application in a Docker container is reduced from 206MB to 50.4MB.
7+
**minicon** is a general tool to analyze applications and executions of these applications to obtain a filesystem that contains all the dependencies that have been detected. In particular, it can be used to reduce Docker containers. The **minicon** package includes **minidock**
8+
which will help to reduce Docker containers by hiding the underlying complexity of running **minicon** inside a Docker container.
89

10+
The purpose of **minicon** and **minidock** is better understood with the use cases explained in depth in the section "[Examples](#4-examples)": the size of a basic UI that contains bash, ip, wget, ssh, etc. commands is _reduced from 211MB to 10.9MB_; the size of a NodeJS application along with the server is _reduced from 686 MB (using the official node image) to 45.6MB_; the size of an Apache server is _reduced from 216MB to 50.4MB_, and the size of a Perl application in a Docker container is _reduced from 206MB to 43.3MB_.
911

10-
> [**minidock**](#minidock---minimization-of-docker-containers) is based on [**minicon**](doc/minicon.md), [**importcon**](doc/importcon.md) and [**mergecon**](doc/mergecon.doc), and hides the complexity of creating a container, mapping minicon, guessing parameters such as the entrypoint or the default command, creating the proper commandline, etc.
12+
> [**minidock**](doc/minidock.md) is based on [**minicon**](doc/minicon.md), [**importcon**](doc/importcon.md) and [**mergecon**](doc/mergecon.md), and hides the complexity of creating a container, mapping minicon, guessing parameters such as the entrypoint or the default command, creating the proper commandline, etc.
1113
12-
## 1. Why **minidock**?
14+
## 1. Why **minicon** and **minidock**?
1315

14-
Reducing the footprint of one container is of special interest, to redistribute the container images and saving the storage space in your premises. There are also security reasons to minimize the unneeded application or environment available in one container image (e.g. if the container does not need a compiler, why should it be there? maybe it would enable to compile a rootkit).
16+
Reducing the footprint of one container is of special interest, to redistribute the container images.
1517

16-
In this sense, the publication of the NIST "[Application Container Security Guide](https://doi.org/10.6028/NIST.SP.800-190)" suggests that "_An image should only include the executables and libraries required by the app itself; all other OS functionality is provided by the OS kernel within the underlying host OS_".
18+
It is of special interest in cases such as [SCAR](https://github.com/grycap/scar), that executes containers out of Docker images in AWS Lambda. In that case, the use cases are limited by the size of the container (the ephemeral storage space is limited to 512 Mb., and SCAR needs to pull the image from Docker Hub into the ephemeral storage and then uncompress it; so the maximum size for the container is even more restricted).
1719

18-
**minicon** is a tool that enables a fine grain minimization for any type of container (it is even interesting for non containerized boxes). Using it for Docker images consist in a simple pipeline:
20+
But there are also security reasons to minimize the unneeded application or environment available in one container image. In the case that the application fails, not having other applications reduces the impact of an intrusion (e.g. if the container does not need a compiler, why should it be there? maybe it would enable to compile a rootkit).
21+
22+
In this sense, the recent publication of the NIST "[Application Container Security Guide](https://doi.org/10.6028/NIST.SP.800-190)" suggests that "_An image should only include the executables and libraries required by the app itself; all other OS functionality is provided by the OS kernel within the underlying host OS_".
23+
24+
**minicon** is a tool that enables a fine grain minimization for any type of filesystem, but it is possible to use it to reduce Docker images following the next pipeline:
1925

2026
1. Preparing a Docker container with the dependencies of **minicon**
2127
1. Guessing the entrypoint and the default command for the container.
2228
1. Running **minicon** for these commands (maping the proper folders to get the resulting tar file).
2329
1. Using **importcon** to import the resulting file to copy the entrypoint and other settings.
2430
1. etc.
2531

26-
**minidock** is a one-liner for that procedure whose aim is just to convert a
32+
**minidock** is a one-liner that automates that procedure to make that reducing a container consist in just to convert a
2733

2834
```bash
2935
$ docker run --rm -it myimage myapp
@@ -35,8 +41,6 @@ into
3541
$ minicon -i myimage -t myimage:minicon -- myapp
3642
```
3743

38-
To obtain the minimized Docker image, and hiding the internal procedure.
39-
4044
## 2. Installation
4145

4246
### 2.1 From packages
@@ -63,13 +67,13 @@ $ yum install ./minicon-1.2-1.noarch.rpm
6367

6468
### 2.2 From sources
6569

66-
**minidock** is a bash script that runs the other applications in the _minicon_ package, to analyze the docker containers. So you just simply need to have a working linux with bash and the other dependencies installed and get the code:
70+
**minicon** are a set of bash scripts. So you just simply need to have a working linux with bash and the other dependencies installed and get the code:
6771

6872
```bash
6973
$ git clone https://github.com/grycap/minicon
7074
```
7175

72-
In that folder you'll have the **minidock** application. Then the commands in the _minicon_ distribution must be in the PATH. So I would suggest to put it in the _/opt_ folder and set the proper PATH var. Otherwise leave it in a folder of your choice and set the PATH variable:
76+
In that folder you'll have the **minicon**, **minidock** and other applications. The commands in the _minicon_ distribution must be in the PATH. So I would suggest to put it in the _/opt_ folder and set the proper PATH var. Otherwise leave it in a folder of your choice and set the PATH variable:
7377

7478
```bash
7579
$ mv minicon /opt
@@ -78,51 +82,37 @@ $ export PATH=$PATH:/opt/minicon
7882

7983
#### 2.2.1 Dependencies
8084

81-
**minidock** depends on the commands _minicon_, _importcon_ and _mergecon_, and the packages _jq_, _tar_ and _docker_. So, you need to install the proper packages in your system.
85+
**minidock** depends on the commands _minicon_, _importcon_ and _mergecon_, and the packages _jq_, _tar_ and _docker_. **minicon** and the others have dependencies on other packages. So, you need to install the proper packages in your system:
8286

8387
**Ubuntu**
8488

8589
```bash
86-
$ apt-get install jq tar
90+
$ apt-get install jq tar libc-bin tar file strace rsync
8791
```
8892

8993
**CentOS**
9094
```bash
91-
$ yum install tar jq which
95+
$ yum install tar jq glibc-common file strace rsync which
9296
```
97+
9398
## 3. Usage
9499

95-
**minidock** has a lot of options. You are advised to run ```./minidock --help``` to get the latest information about the usage of the application.
100+
The **minidock suite** enables to prepare filesystems for running containers. The suite consists in the next commands:
96101

97-
The basic syntax is
102+
1. **minidock** ([doc](doc/minidock.md)) analyzes one existing Docker image, reduces its footprint and leaves the new version in the local Docker registry. It makes use of the other tools in the _minicon_ package.
98103

99-
```bash
100-
$ ./minidock <options> <options for minicon> [ --docker-opts <options for docker> ] -- <run for the container>
101-
```
102-
103-
Some of the options are:
104-
- \<run for the container\>: Is the whole commandline to be analised in the run. These are the same parameters that you would pass to "docker run ... <image> <run for the container>".
105-
> * the aim is that you run "minidock" as if you used a "docker run" for your container.
106-
- **\<options for docker\>**: If you need them, you can include some options that will be raw-passed to the docker run command used during the analysis. (i.e. minidock will executedocker run <options generated> <options for docker> ...). Some examples are mapping volumes (i.e. **-v** Docker flag)
107-
- **\<options for minicon\>**: If you need to, you can add some minicon-specific options. The supported options are --include --exclude --plugin: --exclude will exclude some path, --include will include specific files or folder, and --plugin can be used to configure the _minicon_ plugins.
108-
- **--image \<image\>**: Name of the existing Docker image to minimize.
109-
- **--tag \<tag\>**: Tag for the resulting image (random if not provided).
110-
- **--mode \<mode\>**: Sets the mode to include the used files in the filesystem. There are 4 modes available _skinny_ (default), _slim_, _regular_ and _loose_.
111-
* skinny only includes those files that have been used during the simulation of the commands.
112-
* slim also includes some whole folders that have been opened.
113-
* regular also includes any whole folder that have been checked to exist (e.g. stat).
114-
* loose also includes the whole folders in which are stored the files that have been opened during the simulation.
115-
- **--default-cmd**: Analyze the default command for the containers in the original image.
116-
- **--apt**: Install the dependencies from minicon using apt-get commands (in the container used for the simulation).
117-
- **--yum**: Install the dependencies from minicon using yum commands (in the container used for the simulation).
118-
- **--execution \<full commandline execution\>**: Commandline to analyze when minimizing the container (i.e. that commandline should be able to be executed in the resulting container so the files, libraries, etc. needed should be included).
119-
- **--run \<full commandline run\>**: Similar to _--execution_, but in this case, the Entrypoint is prepended to the commandline (docker exec vs docker run).
120-
- **-2 \<image\>**: If needed, you can merge the resulting minimized image with other. This is very specific for the "mergecon" tool. It is useful for (e.g.) adding a minimal Alpine distro (with _ash_ and so on) to the minimized filesystem.
121-
- **--verbose | -v**: Gives more information about the procedure.
122-
- **--debug**: Gives a lot more information about the procedure.
104+
1. **minicon** ([doc](doc/minicon.md)) aims at reducing the footprint of the filesystem for the container, just adding those files that are needed. That means that the other files in the original container are removed.
105+
106+
1. **importcon** ([doc](doc/importcon.md)) importcon is a tool that imports the contents from a tarball to create a filesystem image using the "docker import" command. But it takes as reference an existing docker image to get parameters such as ENV, USER, WORKDIR, etc. to set them for the new imported image.
107+
108+
1. **mergecon** ([doc](doc/mergecon.md)) is a tool that merges the filesystems of two different container images. It creates a new container image that is built from the combination of the layers of the filesystems of the input containers.
109+
110+
Please refer to the documentation of each command to get help about them.
123111

124112
## 4. Examples
125113

114+
In this section we are including examples on using **minidock**, that makes use of all the other commands. Please refer to the documentation of each command to get examples about each individual command.
115+
126116
### 4.1 Basic Ubuntu UI in less than 11 Mb.
127117

128118
In this example we will create a basic user interface, from ubuntu, that include commands like `wget`, `ssh`, `cat`, etc.
@@ -413,17 +403,4 @@ minicon uc6 7c85b5a104f5 5 seconds ago
413403
minicon uc6fat 1c8179d3ba94 4 hours ago 206MB
414404
```
415405

416-
In this case, the size has been reduced from 206MB to about 43.3MB.
417-
418-
# 5. Flexible Manipulation of Container Filesystems
419-
420-
The **minidock suite** enables to prepare filesystems for running containers. The suite consists in **minidock**, [**minicon**](doc/minicon.md), [**mergecon**](doc/mergecon.md) and [**importcon**](doc/importcon.md):
421-
422-
1. **minidock** ([direct link](minidock---minimization-of-docker-containers)) analyzes one existing Docker image, reduces its footprint and leaves the new version in the local Docker registry. It makes use of the other tools in the _minicon_ package.
423-
424-
1. **minicon** ([direct link](doc/minicon.md)) aims at reducing the footprint of the filesystem for the container, just adding those files that are needed. That means that the other files in the original container are removed.
425-
426-
1. **importcon** ([direct link](doc/importcon.md)) importcon is a tool that imports the contents from a tarball to create a filesystem image using the "docker import" command. But it takes as reference an existing docker image to get parameters such as ENV, USER, WORKDIR, etc. to set them for the new imported image.
427-
428-
1. **mergecon** ([direct link](doc/mergecon.md)) is a tool that merges the filesystems of two different container images. It creates a new container image that is built from the combination of the layers of the filesystems of the input containers.
429-
406+
In this case, the size has been reduced from 206MB to about 43.3MB.

doc/man/importcon

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
.\" Manpage for importcon.
2+
.\" Contact [email protected] to correct errors or typos.
3+
.TH man 1 "01 Mar 2018" "1.2-1" "importcon man page"
4+
.SH NAME
5+
importcon - IMPORT CONtainer copying features
6+
.SH SYNOPSIS
7+
importcon <options> <container filesystem in tar file>
8+
.SH DESCRIPTION
9+
When a container is running, it is possible to export its filesystem to a tar file, using the command
10+
.I docker export <mycontainer>.
11+
Later, it is possible to import that filesystem into Docker to be used as a Docker image, using a command like
12+
.I docker import <mytarfile>.
13+
The problem is that the new container has lost all the parameters from the original image (i.e. ENTRYPOINT, USER, CMD, etc.).
14+
15+
.B importcon
16+
is a script that enables to import a filesystem exported using
17+
.I docker export
18+
into Docker, and to copy the parameters from the original image (i.e. ENTRYPOINT, USER, CMD, VOLUME, etc.)
19+
20+
21+
.SH OPTIONS
22+
.B --image | -i <image>
23+
Name of the existing image to copy the parameters.
24+
25+
.B --tag | -t <tag>
26+
Tag for the image that will be created from the tarfile (random if not provided)
27+
28+
.B --env | -E
29+
Copy ENV settings
30+
31+
.B --entrypoint | -e
32+
Copy ENTRYPOINT settings
33+
34+
.B --expose | -x
35+
Copy EXPOSE settings
36+
37+
.B --onbuild | -o
38+
Copy ONBUILD settings
39+
40+
.B --user | -u
41+
Copy USER settings
42+
43+
.B --volume | -V
44+
Copy VOLUME settings
45+
46+
.B --workdir | -w
47+
Copy WORKDIR settins
48+
49+
.B --cmd | -c
50+
Copy CMD settings
51+
52+
.B --all | -A
53+
Copy all the previous settings: ENV, ENTRYPOINT, EXPOSE, ONBUILD, USER, VOLUME, WORKDIR and CMD.
54+
55+
.B --version
56+
Displays the version of the package and exits.
57+
58+
.B --help | -h
59+
Shows this help and exits.
60+
61+
.SH EXAMPLES
62+
63+
If we take the next Dockerfile
64+
65+
FROM ubuntu
66+
RUN apt-get update && apt-get install -y --force-yes apache2
67+
EXPOSE 80 443
68+
VOLUME ["/var/www", "/var/log/apache2", "/etc/apache2"]
69+
ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
70+
71+
we can build an image using the command
72+
73+
.I docker build . -t tests:apache
74+
75+
Then we can run a container
76+
77+
.I docker run --rm -id -p 10000:80 tests:apache
78+
79+
And export its filesystem to a file:
80+
81+
.I docker export hungry_payne -o myapache.tar
82+
83+
If we simply import the file back to a Docker image
84+
85+
.I docker import myapache.tar tests:myapache
86+
87+
we can check the differences between the configuration of each image for the new containers:
88+
89+
.I docker inspect tests:apache | jq '.[0].Config'
90+
{
91+
...
92+
"Entrypoint": [
93+
"/usr/sbin/apache2ctl",
94+
"-D",
95+
"FOREGROUND"
96+
],
97+
...
98+
}
99+
100+
.I docker inspect tests:myapache | jq '.[0].Config'
101+
{
102+
...
103+
"Entrypoint": null,
104+
...
105+
}
106+
107+
108+
We can see that our new image has all the setting set to empty. We can use
109+
.B importcon
110+
to import the container, taking the original image as reference:
111+
112+
.I importcon -t tests:apacheimportcon -i tests:apache myapache.tar -A
113+
.I docker inspect tests:apacheimportcon | jq '.[0].Config'
114+
{
115+
...
116+
"Entrypoint": [
117+
"/usr/sbin/apache2ctl",
118+
"-D",
119+
"FOREGROUND"
120+
],
121+
...
122+
}
123+
124+
.SH SEE ALSO
125+
minicon(1), minidock(1), jq(1)
126+
127+
.SH AUTHOR
128+
Carlos de Alfonso ([email protected])

doc/man/mergecon

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
.\" Manpage for mergecon.
2+
.\" Contact [email protected] to correct errors or typos.
3+
.TH man 1 "01 Mar 2018" "1.2-1" "mergecon man page"
4+
.SH NAME
5+
mergecon - merge Docker containers
6+
.SH SYNOPSIS
7+
mergecon <options>
8+
9+
.SH DESCRIPTION
10+
Docker containers are built from different layers, and
11+
.B mergecon
12+
is a tool that merges the filesystems of two different container images. It creates a new container image that is built from the combination of the layers of the filesystems of the input containers.
13+
14+
.SH WHY MERGECON?
15+
16+
If you create a minimal application filesystem (i.e. using minicon), you will be able to run your application, but you will not have any other application available for (e.g.) debugging your application.
17+
18+
Using mergecon, you will be able to overlay the files of your container image to other existing container image. In this way, you can overlay your minicon resulting application over a whole ubuntu:latest container. The effect is that you will have the support of a whole operating environment over the minimal container.
19+
20+
On the other side, if you have an application that needs to be compiled and installed, you can create a one-liner installation, and combine that layer with other container. That means that you will be able to compile such image in (e.g.) ubuntu, and create a final container with other flavor (e.g. CentOS).
21+
22+
.SH OPTIONS
23+
.B --first | -1 <image>
24+
Name of the first container image (will use docker save to dump it)
25+
26+
.B --second | -2 <image>
27+
Name of the second container image (will use docker save to dump it) the default behaviour gives more priority to the second image. I.e. in case of overlapping files in both input images, the files in the second image will be exposed to the final image.
28+
29+
.B --tag | -t <name>
30+
Name of the resulting container image. If not provided, the resulting name will be the concatenation of the names of the two input images: <image1>:<image2> (the : in the input image names is removed).
31+
32+
.B --working | -w <folder>
33+
Working folder. If not provided will create a temporary folder in /tmp
34+
35+
.B --list | -l
36+
Lists the layers in the images (useful for filesystem composition).
37+
38+
.B --file | -f <file>
39+
tar file where the resulting image will be created. If not provided, the image will be loaded into docker.
40+
41+
.B --keeptemporary | -k
42+
Keeps the temporary folder. Otherwise, the folder is removed (if it is created by mergecon).
43+
44+
.B --verbose | -v
45+
Gives more information about the procedure.
46+
47+
.B --debug
48+
Gives a lot more information about the procedure.
49+
50+
.SH SEE ALSO
51+
minicon(1)
52+
53+
.SH AUTHOR
54+
Carlos de Alfonso ([email protected])

0 commit comments

Comments
 (0)