Skip to content

Bundling application into Docker image

Stephan Hradek edited this page Feb 25, 2020 · 9 revisions

Dockerfile


FROM alpine:3.4
MAINTAINER Mojolicious

COPY cpanfile /
    # What should go into this? What's its meaning?
ENV EV_EXTRA_DEFS -DEV_NO_ATFORK

RUN apk update && \
  apk add perl perl-io-socket-ssl perl-dbd-pg perl-dev g++ make wget curl && \
  curl -L https://cpanmin.us | perl - App::cpanminus && \
  cpanm --installdeps . -M https://cpan.metacpan.org && \
  apk del perl-dev g++ make wget curl && \
  rm -rf /root/.cpanm/* /usr/local/share/man/*

# USER daemon
# WORKDIR /
# VOLUME ["/data"]
EXPOSE 3000

CMD ["perl", "-MMojolicious::Lite", "-E", "get '/' =>sub { shift->render(text =>'OK!') }; app->start", "daemon"]

cpanfile


requires "EV";
requires "Mojolicious";
requires "Mojo::Pg";
requires "Mojo::Redis2";
requires "Protocol::Redis::XS";
requires "Mojolicious::Plugin::JSON::XS";
requires "Mojo::IOLoop::ReadWriteFork";

Examples of using docker-compose:

When you need to quickly deploy your current source code (assuming that appropriate docker image contains all needed perl modules):

version: '2'

services:
  web:
    image: pavelsr/kayako-dashboard-dev
    container_name: kayako-dashboard
    environment:
      VIRTUAL_HOST: pavelsr.host
      VIRTUAL_PORT: 8080
      # LETSENCRYPT_HOST: pavelsr.host
    volumes:
      - ${PWD}:/root/web/
    working_dir: /root/web
    # command: [perl, server.pl, daemon]
    command: [hypnotoad, -f, server.pl]
    expose:
      - "8080"
    restart: always

  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
    restart: always

It's important to use -f option of hypnotoad because docker containers require their processes to be foreground processes

If you want to test results locally don't forget to add domain at /etc/hosts/