projectatomic / container-best-practices

Container Best Practices
Other
166 stars 70 forks source link

Use reproducible builds #65

Closed hhorak closed 7 years ago

hhorak commented 8 years ago

The following is an example of how we can create a very simple container:

What we must do first is to install and then to run the docker daemon:

#> yum install -y docker
#> systemctl start docker

Then we can download some image, that we'll use as a base of our image. Let's use something we trust, for example Red Hat Enterprise Linux 7.2:

#> docker pull rhel7:7.2

Then, one way to create an image, is simply to run the container:

#> docker run -ti --name mycont rhel7:7.2 bash

Then do some reasonable work, like creating some content -- in this case a file:

[root@a1eefecdacfa /]# echo Hello Dojo > /root/greeting
[root@a1eefecdacfa /]# exit

And finally, using docker commit we can create an image:

#> docker commit mycont
0bdcfc5ba0602197e2ac4609b8101dc8eaa0d8ab114f542ab6b2f15220d0ab22```

The long hash is its identification and we can use it for running containers. However, once we'd decide to do something more complicated, we'd have troubles to make it again.

So, we should always do things the way, we can reproduce it, which means using Dockerfiles instead.

This example results in the same output as the example before, except we can repeat it as many times we want and always get the same output. It also helps understanding the docker itself more as a packaging format, than anything else:

#> cat Dockerfile
FROM rhel7:7.2
RUN echo Hello Dojo > /root/greeting

#> docker build .
baude commented 8 years ago

@hhorak would you mind turning your issue into a pull request?