How to create a Docker image for a Ruby project without build tools?

I am trying to create a Docker image for a Ruby project. The problem is that the project has some dependencies associated with precious stones that should build their own extensions. I understand that I have several options:

  • Start with a base image that already has the build tools installed.
  • Use the base image without build tools, install the build tools as a step in the Docker file before running bundle install.
  • Pre-copy your own extensions on the host, make a gem and just copy the resulting package into the image.

1 and 2 seem to require the resulting image to contain the build tools needed to create custom extensions. I am trying to avoid this scenario for security reasons. 3 is cumbersome but doable and will do what I want.

Are there any options that I am missing, or am I not understanding something?

+1
source share
1 answer

I use parameter 3 all the time, the goal is to end up with an image that only has what I need to execute (not compile)

, Apache, ( ) Apache.

:

if [ "$(docker images -q apache.deb 2> /dev/null)" = "" ]; then
  docker build -t apache.deb -f Dockerfile.build . || exit 1
fi

Dockerfile.build , Apache ( deb)

RUN checkinstall --pkgname=apache2-4 --pkgversion="2.4.10" --backup=no --deldoc=yes --fstrans=no --default
RUN mkdir $HOME/deb && mv *.deb $HOME/deb
VOLUME /root/deb

:

if [ "$(docker images -q apache.inst 2> /dev/null)" = "" ]; then
    docker inspect apache.deb.cont > /dev/null 2>&1 || docker run -d -t --name=apache.deb.cont apache.deb
    docker inspect apache.inst.cont > /dev/null 2>&1 || docker run -u root -it --name=apache.inst.cont --volumes-from apache.deb.cont --entrypoint "/bin/sh" openldap -c "dpkg -i /root/deb/apache2-4_2.4.10-1_amd64.deb"
    docker commit apache.inst.cont apache.inst
    docker rm apache.deb.cont apache.inst.cont
fi

deb, ( "openldap" ) :

docker run -u root -it --name=apache.inst.cont --volumes-from apache.deb.cont --entrypoint "/bin/sh" openldap -c "dpkg -i /root/deb/apache2-4_2.4.10-1_amd64.deb"
docker commit apache.inst.cont apache.inst

, Dockerfile, , .

FROM apache.inst:latest

psmith Docker Rails App from .
, , :

bundle install --without development test && \
apk del build-dependencies

ruby ​​ , .

, gcc Apache ( , , Apache , ...)

+2

Source: https://habr.com/ru/post/1666974/


All Articles