tiagodavi
Hi Guys. I have elixir/phoenix running inside a docker container with docker compose and I realised my project takes much more time to run tests inside docker and it’s needed to compile every single time I run my tests, even by running just one test.
Does anyone know how to solve this problem?
Thanks.
docker-compose.yml
version: "3.4"
services:
db:
image: "mdillon/postgis"
volumes:
- db_store:/var/lib/postgresql/data
ports:
- "5432:5432"
redis:
image: "redis:5.0"
web:
build:
context: .
target: build
args:
MIX_ENV: "dev"
command: '/bin/bash -c "while true; do sleep 10; done;"'
volumes:
- .:/opt/app
- ./priv/ua_inspector:/opt/data/ua_inspector
- build_cache:/opt/cache
- elixir_mix:/root/.mix
depends_on:
- db
- redis
ports:
- "4000:4000"
ulimits:
nofile: 1024
# memlock: 64
nproc: 63090
environment:
- LOCAL_USER_ID=${LOCAL_USER_ID}
env_file: .env.development
tty: true
stdin_open: true
volumes:
db_store: {}
build_cache: {}
elixir_mix: {}
Dockerfile
#########################################################
## BUILD STAGE - Development image with necessary deps ##
#########################################################
FROM verybigthings/elixir:1.8 AS build
ARG WORKDIR=/opt/app
ARG MIX_ENV=prod
ARG APP_USER=user
ENV MIX_ENV=${MIX_ENV}
ENV WORKDIR=$WORKDIR
ENV APP_USER=$APP_USER
ENV MIX_HOME=/opt/cache/mix
ENV HEX_HOME=/opt/cache/hex
ENV BUILD_PATH=/opt/cache/_build
ENV DEPS_PATH=/opt/cache/deps
RUN apt-get update \
&& apt-get install -y \
# wkhtmltopdf \
xvfb \
libssl1.0-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
RUN tar vxf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
RUN cp wkhtmltox/bin/wk* /usr/local/bin/
RUN apt-get update && apt-get install -y \
make vim less bash git locales inotify-tools postgresql-client
# Tool to propagate singals from the container to the app
ENV PID1_VERSION=0.1.2.0
RUN curl -sSL "https://github.com/fpco/pid1/releases/download/v${PID1_VERSION}/pid1-${PID1_VERSION}-linux-x86_64.tar.gz" | tar xzf - -C /usr/local \
&& chown root:root /usr/local/sbin \
&& chown root:root /usr/local/sbin/pid1
WORKDIR $WORKDIR
RUN mix local.hex --force && \
mix local.rebar --force
# Set entrypoint
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["/bin/bash", "-c", "while true; do sleep 10; done;"]
######################################################################################
## PRE-RELEASE STAGE - compiles code and bundles the application to Erlang release ##
######################################################################################
FROM build AS pre-release
ARG APP_NAME
ARG APP_VSN
ENV APP_NAME=${APP_NAME} \
APP_VSN=${APP_VSN}
COPY . .
ENV PHOENIX_VERSION 1.4.3
RUN mix archive.install hex phx_new $PHOENIX_VERSION --force
RUN mkdir -p /opt/built \
&& mix do deps.get, compile --warnings-as-errors \
&& cd assets\
&& yarn install && yarn build \
&& cd .. \
&& mix do phx.digest, release --verbose \
&& cp /opt/cache/_build/${MIX_ENV}/rel/${APP_NAME}/releases/${APP_VSN}/${APP_NAME}.tar.gz /opt/built \
&& cd /opt/built \
&& tar -xzf ${APP_NAME}.tar.gz \
&& rm ${APP_NAME}.tar.gz
############################################
## RELEASE STAGE - production application ##
############################################
FROM debian:9-slim AS release
RUN apt-get update \
&& apt-get install -y \
libssl1.0-dev \
wget \
xz-utils \
libxrender1 \
libfontconfig \
libxext6 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
RUN tar vxf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
RUN cp wkhtmltox/bin/wk* /usr/local/bin/
# Install Aptible CLI tool.
RUN wget https://omnibus-aptible-toolbelt.s3.amazonaws.com/aptible/omnibus-aptible-toolbelt/master/187/pkg/aptible-toolbelt_0.16.2%2B20190829193224~ubuntu.16.04-1_amd64.deb
RUN dpkg -i aptible-toolbelt_0.16.2+20190829193224~ubuntu.16.04-1_amd64.deb
ARG APP_NAME
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
RUN apt-get update && apt-get install -y \
bash git libpq-dev libjson-c-dev
ENV REPLACE_OS_VARS=true \
APP_NAME=${APP_NAME}
WORKDIR /opt/app
COPY ./priv/ua_inspector /opt/data/ua_inspector
COPY --from=pre-release /opt/built .
EXPOSE 4000
CMD trap 'exit' INT; /opt/app/bin/${APP_NAME} foreground
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
Hey there,
It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Quite interesting article Google brought me. Didn’t find any mentions about it here.
What do you think in general? Would you use togethe...
New
:warning: Security advisory: Decimal DoS vulnerability
A vulnerability has been published for decimal where very large exponents can cau...
New
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Other Trending Topics
New episode with Louis Pilfold - the most detailed conversation about Gleam’s design I’ve come across.
Worth knowing for the Elixir comm...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Exadra37
Please add your
Dockerfileanddocker-compose.ymlfiles to your topic so that we can try to figure out what’s going on.Please also remember to say if you are on Linux, Windows or Mac.
tiagodavi
Thank you. I will
tiagodavi
I put Dockerfile and docker-compose.yml
Exadra37
You are using a Dockerfile for build a production release. This is not suitable for development use.
You need to drop a Dockerfile with stages and build everything in one stage.
Also you need to map your entire workdir in the host, and always work inside the docker container.
If you use Elixir in the host and then use inside the docker container you may get weird results because of mismatch in versions of Elixir/Phoenix/Erlang.
See an example in a old learning project of mine:
Dockerfile:
docker-compose.yml:
I use a much more refined Docker stack nowadays, but is not ready to share… sorry.
Anyway you can use the above as a starting point to adapt to your needs.
tiagodavi
Thank you. I’ll try yours.
tiagodavi
I figured out it was a Docker For Mac’s problem. So I found a library called docker-sync that improves volumes performance and everything runs much better:
Exadra37
Good that you speed-ed up volumes mapping, but I still stand for what I said that you are using a Dockerfile format suitable for releases, not for development.
tiagodavi
Actually I knew this was for releases. I know I can use Alpine etc, but I am using this for a specific reason. Thanks.
cnck1387
Have you looked into using the edge version of Docker Desktop? It has a new way of syncing files using “Mutagen” that brings volume mount performance up to native MacOS speeds.
There’s a good speed comparison of it here: File system performance improvements · Issue #1592 · docker/for-mac · GitHub
Personally I run Windows and use Docker Desktop which is really fast so I have no first hand experience using this but other folks who use MacOS have said they’ve seen good results (I run a Docker course so I tend to keep a pulse on Docker things for every OS).
wolf4earth
Alternatively you might want to look into the “consistency” options for mounts on Docker for MacOS. They exist to tune performance of mounts on MacOS.
The default here is
consistentwhich is also the slowest option. When mounting local files into a container then I’ve made good experiences withcached: