Your SlideShare is downloading. ×

Docker perl-build

843

Published on

Example of building a Docker container stack using Gentoo, Perl-5.20 with perl optimized for the local processor. Howto includes steps to find the local Perl configuration, create the Dockerfile, and …

Example of building a Docker container stack using Gentoo, Perl-5.20 with perl optimized for the local processor. Howto includes steps to find the local Perl configuration, create the Dockerfile, and build new containers using this one.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
843
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Mongering Perl in a box: Building a working environment with Docker. Steven Lembark Workhorse Computing lembark@wrkhors.com
  • 2. Fresh, not frozen Pre-compiled perl distros are often un-optimized. They are bulky, slow, and have annoying dependencies. Re-compiling perl each time is false lazyness. What you need is a re-usable perl that meets your needs. Here is how to get just that.
  • 3. Fresh, not frozen Pre-compiled perl distros are often un-optimized. They are bulky, slow, and have annoying dependencies. Re-compiling perl each time is false lazyness. What you need is a re-usable perl that meets your needs. Here is how to get just that. And nothing more.
  • 4. Stackable shipping Goal: perl + PM's you depend on. Modular for development, testing, & deployment. perl optimized for native CPU. Test environment separate from the distro and modules. Result: mix-and-match perl version, modules, test suite.
  • 5. Start by getting docker. They provide shell code for the basics: $curl -sL https://get.docker.io/ | sh; $wget -qO- https://get.docker.io/ | sh; will do the deed on Fedora, Ubunto/Debian, or Gentoo.
  • 6. Docker on Gentoo Don't need to run as su: Add your users to “docker” in /etc/group. After that check that docker is running: $ docker ps; Get access to the repository: $ docker login;
  • 7. Testing the waters Minimal “base” container: busybox. Good for experimenting: $ docker pull busybox Pulling repository busybox fd5373b3d938: Download complete ... f06b02872d52: Download complete
  • 8. Thinking inside the box $ docker run -t -i busybox /bin/sh; # <-- you enter busybox as su! # ping 8.8.8.8; <-- network available. ... # exit; $ <-- back at the original shell
  • 9. You usually need an “O/S” base Docker is designed to require an O/S container. Hard to re-cycle underlying O/S. Upside is that getting the basic material is easy enough. Lots of stock builds for yum, apt-get, packman, emerge.
  • 10. Gentoo is easy to dockerize Common solution is a “stage-3” system. Basic build sufficient to generate a working system. Advantage that you can optimize the remainder. Avoiding bloatware big help with containers.
  • 11. Finding a distribution Start at the docker registry https://registry.hub.docker.com/ Looking for stage-3 builds: https://registry.hub.docker.com/search?q=gentoo+stage3 I find: rndevfx/gentoo-stage3-amd64-nomultilib Looks nice for my opteron...
  • 12. Grabbing an O/S Get the container: $ docker pull rndevfx/gentoo-stage3-amd64-nomultilib; Run it: $ docker run -i -t rndevfx/gentoo-stage3-amd64-nomultilib '/bin/bash'; # gcc --version; gcc (Gentoo 4.7.3-r1 p1.4, pie-0.5.5)... This gcc supports '--arch=native” for optimization.
  • 13. Building a perl container Github has templates: http://github.com/Perl/docker-perl Dockerfiles like “5.020.000-64bit/Dockerfile”. I'll create a new “5.02.0-64bit-optimized” directory.
  • 14. • Original Dockerfile: FROM buildpack-deps # parent container MAINTAINER Peter Martini <PeterCMartini@GMail.com> RUN apt-get update && apt-get install -y curl procps # commands to build perl RUN mkdir /usr/src/perl WORKDIR /usr/src/perl # build dir within the container RUN curl -SL http://www.cpan.org/src/5.0/perl-5.20.0.tar.gz | tar -xz --strip-components=1 RUN ./Configure -Duse64bitall -des && make -j$(nproc) && TEST_JOBS=$(nproc) make test_harness && make install && make veryclean WORKDIR /root CMD ["perl5.20.0","-de0"] # default entry point for interactive container
  • 15. Existing perl Configure arguments $ perl -V; Summary of my perl5 (revision 5 version 18 subversion 1) configuration: Platform: osname=... uname=... config_args='-de -Dprefix=/opt/perl/5.18 -Duseshrplib -Doptimize=-O3 -march=native -pipe' hint=recommended...
  • 16. Custom Dockerfile FROM rndevfx/gentoo-stage3-amd64-nomultilib MAINTAINER Steven Lembark <lembark@wrkhors.com> WORKDIR /var/tmp # each “RUN” creates a new intermediate image & context: # use WORKDIR or “cd perl-5.20.0 && ./Configure...” ; RUN wget http://www.cpan.org/src/5.0/perl-5.20.0.tar.gz; RUN gzip -dc < perl-5.20.0.tar.gz | tar xf -; WORKDIR perl-5.20.0 RUN ./Configure -de -Dprefix=/opt/perl -Duseshrplib -Doptimize='-O3 -march=native -pipe'; RUN make all test install; RUN /opt/perl/bin/h2ph -r -a -l; CMD ["/opt/perl/bin/perl","-d", “-e”, “42” ]
  • 17. Intermediate images Each “RUN” in the build creates a new intermediate image. These can be saved or removed. They are normally cleaned up on the way out. Result: no need to “make distclean”.
  • 18. Building Perl The build option takes a path and optional repository tag. Note that the path is a directory, not the Dockerfile. $ cd /scratch/docker/custom-perl; $ docker build –rm=false –tag='lembark/perl-5.20-barcelona' . ;
  • 19. Checking local containers Scratch images have no tag. The ones here were from testing the build. This one didn't finish: $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE <none> <none> 5906d8edbb59 10 minutes ago 726.1 MB <none> <none> 10f5517fcada 23 minutes ago 726.1 MB <none> <none> 7d328e761704 26 minutes ago 725.5 MB <none> <none> 88f1e41aaed5 27 minutes ago 725.5 MB <none> <none> 28052ace7e04 28 minutes ago 725.5 MB <none> <none> 6f46836220d9 31 minutes ago 725.5 MB rndevfx/gentoo-stage3-amd64-nomultilib latest e9d0ce66148c 3 months ago 638.2 MB
  • 20. $ docker build --rm=false --tag=lembark/perl-5.20.0-barcelona .; Step 0 : FROM rndevfx/gentoo-stage3-amd64-nomultilib ---> e9d0ce66148c Step 1 : MAINTAINER Steven Lembark ---> Using cache <-- recycled image ---> 41d5480e49e7 Step 2 : WORKDIR /var/tmp ---> Using cache ---> 010d3d70ced1 ... Step 7 : RUN make all test install; <-- first execution is here. ---> Running in 949c9ddfc2ef ... -r and -a options are mutually exclusive <-- error from h2ph
  • 21. True Lazyness Running “build” caches everything through h2ph: ... Step 7 : RUN make all test install; ---> Using cache ---> cb4c5cd0607e Step 8 : RUN /opt/perl/bin/h2ph -r -l /usr/include; ---> Running in 92efee8c31e2 require '_h2ph_pre.ph'; ...
  • 22. And impatience Change CMD, re-run the build uses caches: $ time docker build --rm=false --tag=lembark/perl-5.20.0-barcelona . Sending build context to Docker daemon 4.096 kB Sending build context to Docker daemon Step 0 : FROM rndevfx/gentoo-stage3-amd64-nomultilib ... Step 9 : CMD [ "/opt/perl/bin/perl","-d", "-e 0" ] ---> Using cache ---> f7b83ecbe276 Successfully built f7b83ecbe276 real 0m0.241s user 0m0.019s sys 0m0.012
  • 23. Visions of images Successful build generates an image: $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE lembark/perl-5.20.0-barcelona latest f7b83ecbe276 5 minutes ago 879.8 MB <none> <none> 7c3e670e5691 12 minutes ago 879.8 MB <none> <none> 506b8acd8c71 15 minutes ago 871.8 MB <none> <none> 10f5517fcada About an hour ago 726.1 MB <none> <none> 7d328e761704 About an hour ago 725.5 MB <none> <none> 88f1e41aaed5 About an hour ago 725.5 MB <none> <none> 28052ace7e04 About an hour ago 725.5 MB <none> <none> 6f46836220d9 About an hour ago 725.5 MB rndevfx/gentoo-stage3-amd64-nomultilib latest e9d0ce66148c 3 months ago 638.2 MB
  • 24. Welcome to perl “CMD” gets run with an interactive container: $ docker run -i -t lembark/perl-5.20.0-barcelona; Loading DB routines from perl5db.pl version 1.44 Editor support available. ... main::(-e:1): 0 DB<1> x $^V v5.20.0
  • 25. Have it your way $ docker run -i -t lembark/perl-5.20.0-barcelona /opt/perl/bin/perl -MCPAN -e shell; CPAN.pm requires configuration, but most of it can be done ... Would you like to configure as much as possible automatically? A “module” container's Dockerfile: FROM lembark/perl-5.20.0-barcelona RUN perl -MCPAN -e 'install DBI' RUN perl -MCPAN -e 'install DBD::Pg'
  • 26. On the shoulders of giants Now you can run on Perl. Install the application into, say, /opt/foo. Your Dockerfile includes: FROM lembark/perl-5.20.0-modules CMD [ “/opt/perl/bin/perl”,”/opt/foo/bin/foo”, “--bar”]
  • 27. Test containers stack on top of apps Build foo/bar-test “FROM foo/bar”! docker run foo/bar; run the application. docker run foo/bar-test; run your tests. Test code and libraries are not in the application.
  • 28. References http://docs.docker.com/ .../builder Dockerfile directives .../userguide What you think it is.
  • 29. Summary Docker makes lxc approachable. Can't easily recycle underlying O/S. But O/S containers are straightforward. Bundling O/S, language, application is easy enough. Stacking separates applications, tests, versions easily.

×