Docker can do a lot more than you might think, I'll show you how to do those things.
Background
I’m in charging a system with Debian8 + Ruby2.1 + Puppet3.7.
We need to migrate to Debian9, It relies on Puppet3.7 so much that we couldn’t change it.
We need to build a static linked Ruby+Puppet, and ensure it will run in Debian9 or Debian10
Why Docker?
Why would we bother Docker to build instead of using a Debian8 machine simply?
Unless we get a pure Debian8 host, there are plenty dependicies binding with the system
It seems that Virtual Machine could do this job, but it’s a little overweight.
The official Debian image is pure and easily to start and stop, what’s more, we could use the cached layers.
# upgrade & install required packages RUNecho"deb http://mirrors.163.com/debian/ jessie main non-free contrib\n \ deb-src http://mirrors.163.com/debian/ jessie main non-free contrib\n \ deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib\n \ deb-src http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib" > /etc/apt/sources.list
# Ruby build system RUN apt-get update && apt-get upgrade && apt-get install -y wget ruby-build
WORKDIR /home
# Download source package RUN wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz RUN wget https://downloads.puppetlabs.com/puppet/puppet-3.7.2.tar.gz RUN tar -zxf ruby-2.1.5.tar.gz RUN tar -zxf puppet-3.7.2.tar.gz
RUNcd ruby-2.1.5 \ && ./configure --prefix=/opt/puppet37 --disable-install-doc --disable-install-rdoc --disable-install-capi \ && make -j8 \ && make install
# In debian9, there is no library, wo need copy it. RUNcp /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 /opt/puppet37/lib/ RUNcp /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 /opt/puppet37/lib/
# Must specify the version, newer facter will block the puppet. RUN /opt/puppet37/bin/gem install hiera -v 1.3.4 RUN /opt/puppet37/bin/gem install facter -v 2.2.0
# Install Puppet RUN /opt/puppet37/bin/ruby /home/puppet-3.7.2/install.rb --no-rdoc
# make a package RUN tar -cf puppet37_2_1_5.tar /opt/puppet37 RUN xz -9 puppet37_2_1_5.tar