Why does this docker-compose command fail while docker run command succeeds? - perl

I have the following docker-compose.yml:
db:
image: postgres
search:
image: elasticsearch
web:
build: .
working_dir: /code
environment:
CATALYST_CONFIG_LOCAL_SUFFIX: development
volumes:
- .:/code
ports:
- "8000:8000"
links:
- db
- search
command: carton exec plackup -E development bicycleevents_web.psgi -p 8000
Edit: and the following Dockerfile:
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y --force-yes build-essential curl libssl-dev postgresql-client libpq-dev perl-doc
RUN apt-get clean
RUN curl -L https://cpanmin.us | perl - --sudo App::cpanminus
RUN cpanm Carton
RUN mkdir /code
WORKDIR /code
ADD . /code/
RUN rm -rf /code/local/
RUN carton install
If I run docker-compose up the carton exec ... command fails:
$ docker-compose up
...
Starting bicycleeventsweb_web_1
web_1 | Error while loading /code/bicycleevents_web.psgi: Can't locate Moose.pm in #INC (you may need to install the Moose module) (#INC contains: /code/lib /code/local/lib/perl5 /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at /code/lib/BicycleEvents/Web.pm line 2.
web_1 | BEGIN failed--compilation aborted at /code/lib/BicycleEvents/Web.pm line 2.
web_1 | Compilation failed in require at /code/bicycleevents_web.psgi line 6.
web_1 | BEGIN failed--compilation aborted at /code/bicycleevents_web.psgi line 6.
bicycleeventsweb_web_1 exited with code 2
...
However, if I run the same command manually on the container, it succeeds:
$ docker run -i -t -e "CATALYST_CONFIG_LOCAL_SUFFIX=development" bicycleeventsweb_web carton exec plackup -E development bicycleevents_web.psgi -p 8000
...
HTTP::Server::PSGI: Accepting connections at http://0:8000/
Any thoughts on what is different between the two commands?
For reference carton is like Bundler for Perl. Using carton exec should setup the Perl environment so that the appropriate library paths are included that contain all the application specific dependencies - as works with the docker run command.

Can we see the Dockerfile that's being built, please? (I lack the reputation to ask in a comment. Edit: Thanks! )
(Edit:)
One difference I notice is that you're mounting . to /code in your docker-compose file, but you're not when running the command manually. I'm not familiar with Carton specifically, but if it's creating artifacts inside /code when you're executing carton install in the Dockerfile, you might be losing them as a result of your docker-compose volumes definition.

Related

running elixir on buildkite with docker-compose fails with dependencies

i have the following dockerfile for an elixir+phoenix app
FROM elixir:latest as build_base
RUN apt-get -y update
RUN apt-get -y install inotify-tools curl
ARG TARGETARCH
RUN if [ ${TARGETARCH} = arm64 ]; then \
curl -L -o /tmp/dart-sass.tar.gz https://github.com/sass/dart-sass/releases/download/1.54.5/dart-sass-1.54.5-linux-${TARGETARCH}.tar.gz \
;else \
curl -L -o /tmp/dart-sass.tar.gz https://github.com/sass/dart-sass/releases/download/1.54.5/dart-sass-1.54.5-linux-x64.tar.gz \
;fi
RUN tar -xvf /tmp/dart-sass.tar.gz -C /tmp
RUN mv /tmp/dart-sass/sass /usr/local/bin/sass
RUN mkdir -p /app
WORKDIR /app
COPY mix.* ./
RUN mix local.hex --force
RUN mix archive.install hex phx_new --force
RUN mix local.rebar --force
RUN mix deps.clean --all
RUN mix deps.get
RUN mix --version
RUN mix deps.compile
COPY assets assets
COPY vendor vendor
COPY lib lib
COPY config config
COPY priv priv
COPY test test
RUN mix compile
the docker-compose file looks like the following
services:
web:
build:
context: .
dockerfile: Dockerfile
target: build_base
volumes:
- ./:/app
ports:
- "80:80"
command: mix phx.server
I'm trying to run docker-compose as part of the build step in buildkite, this is an extract of the step in buildkite
- label: "run web"
key: "web"
commands:
- mix phx.server
plugins:
- docker-compose#v4.9.0:
run: web
config: docker-compose.yml
however when running web i see everything happens properly including the package installation, however when running the application i see the following error
web_1 | Unchecked dependencies for environment dev:
web_1 | * telemetry_metrics (Hex package)
web_1 | the dependency is not available, run "mix deps.get"
and the list goes on and on, this works fine on my local machine, its only when running on buildkite. does anyone have any idea on how to fix this ?

Can't locate Bio/SeqIO.pm in #INC

Hi I am trying to install VelvetOptimizer using docker. and it say Can't locate Bio/SeqIO.pm in #INC. It requires the following to be installed:
Velvet >= 0.7.51 ,Perl >= 5.8, BioPerl >= 1.4 and i have installed them
Please find the Dockerfile:
FROM amazonlinux
WORKDIR /shared
RUN yum -y install gcc
ADD http://www.cpan.org/src/5.0/perl-5.16.1.tar.gz /shared
RUN tar -xzf perl-5.16.1.tar.gz
WORKDIR /shared/perl-5.16.1
RUN ./Configure -des -Dprefix=/shared/perl-5.16.1/localperl
RUN make
RUN make test
RUN make install
RUN echo “Perl Installation Complete”
ENV PATH=/shared/perl-5.16.1/localperl/bin/:${PATH}
WORKDIR /shared
ADD http://www.ebi.ac.uk/~zerbino/velvet/velvet_latest.tgz .
RUN tar -xvf /shared/velvet_latest.tgz
WORKDIR /shared/velvet_1.2.10/
RUN make
ENV PATH=${PATH}:/shared/velvet_1.2.10/
WORKDIR /shared
RUN echo "BIO PERL INSTALLATION"
RUN \wget -O - https://install.perlbrew.pl | bash
ENV PATH=${PATH}:/root/perl5/perlbrew/bin/
RUN perlbrew install-cpanm
RUN cpanm Bio::Perl
WORKDIR /shared
ADD http://www.vicbioinformatics.com/VelvetOptimiser-2.2.5.tar.gz .
RUN tar zxvf VelvetOptimiser-2.2.5.tar.gz
ENV PATH=${PATH}:/shared/VelvetOptimiser-2.2.4
When I run the command/shared/VelvetOptimiser-2.2.5/VelvetOptimiser.pl
I get the below error:
Error:
Can't locate Bio/SeqIO.pm in #INC (#INC contains: /shared/VelvetOptimiser-2.2.5 /shared/vcftools/src/perl /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /shared/VelvetOptimiser-2.2.5/VelvetOpt/Assembly.pm line 238.
BEGIN failed--compilation aborted at /shared/VelvetOptimiser-2.2.5/VelvetOpt/Assembly.pm line 238.
Compilation failed in require at /shared/VelvetOptimiser-2.2.5/VelvetOptimiser.pl line 37.
BEGIN failed--compilation aborted at /shared/VelvetOptimiser-2.2.5/VelvetOptimiser.pl line 37.
But when I use "find" command: I am able to find the files.
./root/.cpanm/work/1501770319.1/BioPerl-1.007001/blib/lib/Bio/SeqIO.pm
./root/.cpanm/work/1501770319.1/BioPerl-1.007001/Bio/SeqIO.pm
./shared/perl-5.16.1/localperl/lib/site_perl/5.16.1/Bio/SeqIO.pm
I think its not be found in Perl's include path, which is represented by the variable named #INC.
Can anyone please let me know how to fix this issue. how to add it in perls include path.
Clearly, /shared/VelvetOptimiser-2.2.5/VelvetOptimiser.pl has
#!/usr/bin/env perl
as its shebang line. So, it will use the first perl it finds in the $PATH.
You likely have a perl in /usr/bin. In your Docker file, you have:
ENV PATH=${PATH}:/root/perl5/perlbrew/bin/
That is, you likely put /usr/bin ahead of the perlbrew directory. So, /usr/bin/env perl is picking up /usr/bin/perl and not the perl you installed via perlbrew (which is also where you installed your new perl).
So, try
ENV PATH=/root/perl5/perlbrew/bin/:${PATH}
In addition, I do not see you actually install a perl via perlbrew:
You need
perlbrew install 5.xx.x
perlbrew switch 5.xx.x
before installing cpanm and installing Bio::Perl.

Fail to install Starman inside Docker container

I'm trying to create a Docker container for an app with starman perl server
So my Dockerfile looks like this :
FROM perl:latest
MAINTAINER perl5 drd.trif#gmail.com
RUN curl -L http://cpanmin.us | perl - App::cpanminus
RUN cpanm Carton Starman
RUN cachebuster=b953b35 git clone -b pb_on_docker --single-branch https://github.com/DragosTrif/PearlBee.git
RUN cd PearlBee && carton install && carton install --deployment
EXPOSE 8080
WORKDIR PearlBee
CMD carton exec starman --port 8080 bin/app.psgi
But it fails to install Starman
I checked the build.log and found this error :
2016/09/27-08:18:16 Starman::Server (type Net::Server::PreFork) starting! pid(13467)
Missing port in hashref passed in port argument.
2016/09/27-08:41:17 Starman::Server (type Net::Server::PreFork) starting! pid(13468)
Missing port in hashref passed in port argument.
How can i fix this ?

Starting services at container startup

I'm trying to run 3 services at my container startup (snmpd, sshd and centengine)
As runlevel is unknown in the container, services won't start.
I built an image with this Dockerfile :
FROM centos:6.7
MAINTAINER nael <me#mail>
# Update CentOS
RUN yum -y update
# Install wget
RUN yum install -y wget
# Get Centreon Repo
RUN wget http://yum.centreon.com/standard/3.0/stable/ces-standard.repo -O /etc/yum.repos.d/ces-standard.repo
# Install Packages (SSH, sudo, Centreon Poller & Engine, SNMP)
RUN yum install -y --nogpgcheck openssh-clients openssh-server centreon-poller-centreon-engine sudo net-snmp net-snmp-utils
# Install supervisord
RUN rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
RUN yum --enablerepo=epel install -y supervisor
RUN mv -f /etc/supervisord.conf /etc/supervisord.conf.org
ADD supervisord.conf /etc/
# For sshd & centengine
EXPOSE 22 5669
# Change user password
RUN echo -e "password" | (passwd --stdin user)
# Disable PAM (causing issues while ssh login)
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config
# Start supervisord
CMD ["/usr/bin/supervisord"]
Here is the supervisord.conf file
[supervisord]
nodaemon=true
pidfile=/var/run/supervisord.pid
logfile=/var/log/supervisor/supervisord.log
[program:centengine]
command=service centengine start
[program:snmpd]
command=service snmpd start
[program:sshd]
command=service sshd start
But with this Dockerfile and supervisord.conf, when I start my container theses services aren't running.
What could be the problem ?
Not anymore using supervisord.
I just include a script with all the services ... start commands in the Dockerfile. When I create my container with docker run ... I just specify that I want to start it with my script.
& that's working very well.
Thanks #warmoverflow for trying to solve this.
You may find my dockerfy utility useful starting services, pre-running initialization commands before the primary command starts. See https://github.com/markriggins/dockerfy
For example:
RUN wget https://github.com/markriggins/dockerfy/releases/download/0.2.4/dockerfy-linux-amd64-0.2.4.tar.gz; \
tar -C /usr/local/bin -xvzf dockerfy-linux-amd64-*tar.gz; \
rm dockerfy-linux-amd64-*tar.gz;
ENTRYPOINT dockerfy
COMMAND --start bash -c "while false; do echo 'Ima Service'; sleep 1; done" -- \
--reap -- \
nginx
Would run a bash script as a service, echoing "Ima Service" every second, while the primary command nginx runs. If nginx exits, then the "Ima Service" script will automatically be stopped.
As an added benefit, any zombie processes left over by nginx will be automatically cleaned up.
You can also tail log files such as /var/log/nginx/error.log to stderr, edit nginx's configuration prior to startup and much more

How to start railo service in background on the Docker

My name Trang,
I have created Docker image on https://registry.hub.docker.com/u/trangunghoa/railo-mysql/
It is run ok.
Now I created Dockerfile but I can't start automatic Railo service. Please help me.
I have start by some commands at shell script:
exec /opt/railo/railo_ctl start
exec /opt/railo/railo_ctl start -D FOREGROUND
service railo_ctl restart
exec service railo_ctl restart
No command it work.
I looked inside your Dockerfile and identified the problem.
You can only use one CMD inside a Dockerfile. (if you use multiple CMD the old one will override) More info : https://docs.docker.com/reference/builder/#cmd
You need to know that Docker isn't made for running multiple process without a little bit of help. I suggest using supervisord : https://docs.docker.com/articles/using_supervisord/
You can't use RUN service inside a Dockerfile, the reason is simple the command service will be executed and start a daemon, then notify the execution was successful. The temporary container will be killed (and the daemon too) and after that the change will be committed.
What your Dockerfile should look like :
FROM ubuntu:trusty
MAINTAINER Trang Lee <trangunghoa#gmail.com>, Seta International Vietnam(info#setacinq.vn)
#Install base packages
RUN apt-get -y update
RUN apt-get install -y openjdk-7-jre-headless
RUN apt-get install -y tomcat7 tomcat7-admin apache2 libapache2-mod-jk
RUN apt-get purge -y openjdk-6-jre-headless icedtea-6-jre-cacao openjdk-6-jre-lib icedtea-6-jre-jamvm
RUN apt-get install -y supervisor
# config to enable .htaccess
ADD apache_default /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
# start service
ADD start-apache2.sh /start-apache2.sh
ADD railo.sh /railo.sh
ADD run.sh /run.sh
RUN chmod +x /*.sh
#RUN sudo service apache2 start
# install railo
RUN apt-get install -y wget
RUN wget http://www.getrailo.org/railo/remote/download42/4.2.1.000/tomcat/linux/railo-4.2.1.000-pl2-linux-x64-installer.run
RUN chmod -R 744 railo-4.2.1.000-pl2-linux-x64-installer.run
RUN ./railo-4.2.1.000-pl2-linux-x64-installer.run --mode unattended --railopass “123456”
# remove railo setup
#RUN rm -rf railo-4.2.1.000-pl2-linux-x64-installer.run
#RUN sudo service railo_ctl start
RUN mkdir -p /etc/service/railo
ADD start-railo.sh /etc/service/railo/run
RUN chmod 755 /etc/service/railo/run
# EXPOSE <port>
EXPOSE 80 8888
#CMD ["/railo.sh"]
#CMD ["/start-apache2.sh"]
# Supervisord configuration
RUN mkdir /var/log/supervisor
ADD ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]
With your supervisord.conf file looking something like that :
[supervisord]
nodaemon=true
[program:apache2]
command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"
[program:railo]
command=/bin/bash -c "exec /opt/railo/railo_ctl start -D FOREGROUND"