ambareesha7

ambareesha7

How to run cli command from container_1 onto in container_2 in a docker-compose setup

I have Elixir/Phoenix server, based on user requirements server generates markdown and latex files, then it runs System.cmd("pandoc", [relevant commands]) to generate PDF files everything works fine in the local system, here the dependencies are (pandoc and latex) installed locally

now I’m trying to dockerize the project.
I tried installing pandoc and latex in phoenix_server container and it worked fine but the final docker image size increased to 8.5GB because texlive itself has 7.5GB so its not an option

I found this pandoc/latex:2.18 image

so my idea is to create 3 docker containers and run docker-compose up

container_1: Phoenix_server
container_2: postgres:14
container_3: pandoc/latex:2.18

but it didn’t worked.

challenges:

1 sharing server generated file’s with pandoc/latex container, for this I’m thinking to using docker volume option

2 I could not figure out how to run cli commands from phoenix container onto in pandoc/latex container

any help is greatly appreciated

Thank you

Marked As Solved

ambareesha7

ambareesha7

I figured out how to reduce docker image size and install all dependencies in same phoenix container through lot of trial and errors current image size is 2.23gb from 8.5gb
the Dockerfile contains this now:

FROM hexpm/elixir:1.13.0-erlang-24.0.5-ubuntu-focal-20210325

RUN apt-get update && \
    apt-get install -y \
    postgresql-client inotify-tools 

RUN DEBIAN_FRONTEND=noninteractive apt-get install -y \
    build-essential xorg libssl-dev libxrender-dev git wget gdebi xvfb \
    # Install wkhtml to pdf
    wkhtmltopdf \
    # Install pandoc
    pandoc \
    # Install latex
    # texlive-latex-base \
    # texlive-latex-recommended \
    # texlive-pictures \
    # texlive \
    texlive-fonts-recommended \
    texlive-plain-generic \
    texlive-latex-extra \
    texlive-xetex

RUN echo "xvfb-run -a -s \"-screen 0 640x480x16\" wkhtmltopdf \"\$@\"" >/usr/local/bin/wkhtmltopdf-wrapper && chmod +x /usr/local/bin/wkhtmltopdf-wrapper
WORKDIR /app
COPY config /app/config
COPY lib /app/lib
COPY mix.exs mix.lock /app/
COPY priv priv
COPY assets assets
COPY entrypoint.sh /app/

RUN mix local.hex --force && \
    mix local.rebar --force && \
    mix deps.get
RUN mix do compile

CMD ["bash", "/app/entrypoint.sh"]

the final image size may reduce a little more if I use mix release
so I’m settling with the above dockerfile setup
and I found this useful link while searching for a relevant solution, just posting it here for future reference
How to execute command from one docker container to another

Also Liked

al2o3cr

al2o3cr

I’m not following the logic at the end there: what’s the problem with a large image?

al2o3cr

al2o3cr

If you’re eventually deploying to k8s, you don’t want to start out using Docker-specific features like volume.

One approach that works cleanly across all deployment methods is to wrap a network service around the pandoc CLI: something that speaks your favorite network protocol (HTTP + JSON, gRPC, whatever) and accepts arguments + directions for where to put the output. Given that TeX can take a while, it probably needs to implement some kind of status tracking (“is my run of pandoc complete yet?”) or similar.

I’ve built something similar at a previous job. We needed to combine PDFs using a library only available on the JVM, so we wrote a small HTTP interface using Sinatra and JRuby (our team had a lot of folks who knew Ruby as well as Elixir). It accepted S3 URLs for the input PDFs and a webhook URL to notify when the output was available on S3.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement