Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker: introduce multi-stage image build (master, latest) #1085

Merged
merged 1 commit into from
Feb 24, 2018

Conversation

Copy link
Member

@ArthurHoaro ArthurHoaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had never heard of multi stage build before your comment. It seems really nice for production images.


RUN apk --update --no-cache add \
ca-certificates \
curl \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does php7-curl work without curl package?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK php7.0-curl only needs libcurl (on Debian it depends on libcurl3)

Copy link
Member Author

@virtualtam virtualtam Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curl provides the command-line tool that was used to retrieve Shaarli archives; this step has been moved to the composer build stage

php7-curl depends on libcurl: https://pkgs.alpinelinux.org/package/v3.6/community/x86_64/php7-curl (collapsed dependency section on the right)

@virtualtam
Copy link
Member Author

@ArthurHoaro this is indeed helpful in a number of ways:

  • reducing final image size by not including build dependencies
  • reducing the attack surface by not including software not needed at run time
  • providing a clearer, more maintainable build process

@nodiscc
Copy link
Member

nodiscc commented Feb 15, 2018

Will dockerhub autobuild pick up only the alpine-based images, and discard the composer images? I mean the composer images shouldn't be listed on shaarli's dockerhub image list. Otherwise very nice!

@virtualtam
Copy link
Member Author

@nodiscc when building, only the final image gets tagged; here are the log and results of building the master image:

$ docker build -t shaarli:master -f Dockerfile.master .                                                                                                                                   

Sending build context to Docker daemon  18.94kB
Step 1/16 : FROM composer:latest as composer
 ---> 2f3f191337e9
Step 2/16 : RUN curl -L https://github.com/shaarli/Shaarli/archive/master.tar.gz | tar xzf -     && mv Shaarli-master shaarli     && cd shaarli     && composer --prefer-dist --no-dev install
 ---> Running in 145de32b1255
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   123    0   123    0     0    123      0 --:--:-- --:--:-- --:--:--   173
100 1771k    0 1771k    0     0   442k      0 --:--:--  0:00:04 --:--:--  509k
Loading composer repositories with package information
Installing dependencies from lock file
Package operations: 13 installs, 0 updates, 0 removals
  - Installing erusev/parsedown (1.6.0): Downloading (100%)         
  - Installing gettext/languages (2.3.0): Downloading (100%)         
  - Installing gettext/gettext (v4.4.3): Downloading (100%)         
  - Installing psr/log (1.0.2): Downloading (100%)         
  - Installing pubsubhubbub/publisher (dev-master 0d224da): Downloading (100%)         
  - Installing katzgrau/klogger (1.2.1): Downloading (100%)         
  - Installing shaarli/netscape-bookmark-parser (v2.0.5): Downloading (100%)         
  - Installing psr/http-message (1.0.1): Downloading (100%)         
  - Installing psr/container (1.0.0): Downloading (100%)         
  - Installing pimple/pimple (v3.2.3): Downloading (100%)         
  - Installing nikic/fast-route (v1.2.0): Downloading (100%)         
  - Installing container-interop/container-interop (1.2.0): Downloading (100%)         
  - Installing slim/slim (3.9.2): Downloading (100%)         
Generating autoload files
Removing intermediate container 145de32b1255
 ---> aa5f41c9e000
Step 3/16 : FROM alpine:3.6
 ---> 77144d8c6bdc
Step 4/16 : LABEL maintainer="Shaarli Community"
 ---> Running in ddabea36089b
Removing intermediate container ddabea36089b
 ---> 7cc4f30c1a61
Step 5/16 : RUN apk --update --no-cache add         ca-certificates         nginx         php7         php7-ctype         php7-curl         php7-fpm         php7-gd         php7-iconv         php7-intl         php7-json         php7-mbstring         php7-openssl         php7-session         php7-xml         php7-zlib         s6
 ---> Running in 740db3ee5ced
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
(1/45) Installing ca-certificates (20161130-r2)
(2/45) Installing pcre (8.41-r0)
(3/45) Installing nginx (1.12.2-r1)
Executing nginx-1.12.2-r1.pre-install
(4/45) Installing php7-common (7.1.14-r0)
(5/45) Installing ncurses-terminfo-base (6.0_p20171125-r0)
(6/45) Installing ncurses-terminfo (6.0_p20171125-r0)
(7/45) Installing ncurses-libs (6.0_p20171125-r0)
(8/45) Installing libedit (20170329.3.1-r2)
(9/45) Installing libxml2 (2.9.5-r0)
(10/45) Installing php7 (7.1.14-r0)
(11/45) Installing php7-ctype (7.1.14-r0)
(12/45) Installing libcurl (7.58.0-r0)
(13/45) Installing php7-curl (7.1.14-r0)
(14/45) Installing php7-fpm (7.1.14-r0)
(15/45) Installing libxau (1.0.8-r1)
(16/45) Installing libbsd (0.8.3-r3)
(17/45) Installing libxdmcp (1.1.2-r3)
(18/45) Installing libxcb (1.12-r0)
(19/45) Installing libx11 (1.6.5-r0)
(20/45) Installing libxext (1.3.3-r1)
(21/45) Installing libice (1.0.9-r1)
(22/45) Installing libuuid (2.28.2-r2)
(23/45) Installing libsm (1.2.2-r0)
(24/45) Installing libxt (1.1.5-r0)
(25/45) Installing libxpm (3.5.12-r0)
(26/45) Installing libbz2 (1.0.6-r5)
(27/45) Installing libpng (1.6.29-r1)
(28/45) Installing freetype (2.7.1-r1)
(29/45) Installing libjpeg-turbo (1.5.1-r0)
(30/45) Installing libwebp (0.6.0-r0)
(31/45) Installing php7-gd (7.1.14-r0)
(32/45) Installing php7-iconv (7.1.14-r0)
(33/45) Installing libgcc (6.3.0-r4)
(34/45) Installing libstdc++ (6.3.0-r4)
(35/45) Installing icu-libs (58.2-r2)
(36/45) Installing php7-intl (7.1.14-r0)
(37/45) Installing php7-json (7.1.14-r0)
(38/45) Installing php7-mbstring (7.1.14-r0)
(39/45) Installing php7-openssl (7.1.14-r0)
(40/45) Installing php7-session (7.1.14-r0)
(41/45) Installing php7-xml (7.1.14-r0)
(42/45) Installing php7-zlib (7.1.14-r0)
(43/45) Installing skalibs (2.5.1.1-r0)
(44/45) Installing execline (2.3.0.1-r0)
(45/45) Installing s6 (2.5.1.0-r0)
Executing busybox-1.26.2-r9.trigger
Executing ca-certificates-20161130-r2.trigger
OK: 66 MiB in 56 packages
Removing intermediate container 740db3ee5ced
 ---> 7ef8b3e74394
Step 6/16 : COPY nginx.conf /etc/nginx/nginx.conf
 ---> 7d9d4f7c7816
Step 7/16 : COPY php-fpm.conf /etc/php7/php-fpm.conf
 ---> 8cde7ed2a948
Step 8/16 : COPY services.d /etc/services.d
 ---> f3550e9bb4d9
Step 9/16 : RUN rm -rf /etc/php7/php-fpm.d/www.conf     && sed -i 's/post_max_size.*/post_max_size = 10M/' /etc/php7/php.ini     && sed -i 's/upload_max_filesize.*/upload_max_filesize = 10M/' /etc/php7/php.ini
 ---> Running in 123b72f3b77b
Removing intermediate container 123b72f3b77b
 ---> 0c444992aac1
Step 10/16 : WORKDIR /var/www
Removing intermediate container 91a0437bae6c
 ---> 1d67a851891d
Step 11/16 : COPY --from=composer /app/shaarli shaarli
 ---> 73594aae3ae7
Step 12/16 : RUN chown -R nginx:nginx .
 ---> Running in 104f20f33fdd
Removing intermediate container 104f20f33fdd
 ---> 159a3d8cfc16
Step 13/16 : VOLUME /var/www/shaarli/data
 ---> Running in 9156e799672a
Removing intermediate container 9156e799672a
 ---> b70373eb75bb
Step 14/16 : EXPOSE 80
 ---> Running in a02e2292cce2
Removing intermediate container a02e2292cce2
 ---> df9723118bcc
Step 15/16 : ENTRYPOINT ["/bin/s6-svscan", "/etc/services.d"]
 ---> Running in a54ce9e7a914
Removing intermediate container a54ce9e7a914
 ---> 8eb9ff5b9b73
Step 16/16 : CMD []
 ---> Running in 88ff5c328d1e
Removing intermediate container 88ff5c328d1e
 ---> 857d15135e13

Successfully built 857d15135e13
Successfully tagged shaarli:master
$ docker images

REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
shaarli             master              857d15135e13        About a minute ago   71.7MB
<none>              <none>              aa5f41c9e000        About a minute ago   151MB
composer            latest              2f3f191337e9        7 days ago           146MB
alpine              3.6                 77144d8c6bdc        5 weeks ago          3.97MB
alpine              latest              e21c333399e0        2 months ago         4.14MB

@virtualtam virtualtam merged commit ddd3c19 into shaarli:master Feb 24, 2018
@virtualtam virtualtam deleted the docker/multi-stage branch February 24, 2018 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker containers & cloud enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants