Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 432
Adam Taylor Avatar asked Mar 28 '16 09:03

Adam Taylor


People also ask

What is difference between Docker compose up and run?

The key difference between docker run versus docker-compose is that docker run is entirely command line based, while docker-compose reads configuration data from a YAML file. The second major difference is that docker run can only start one container at a time, while docker-compose will configure and run multiple.

What happens when you run Docker compose up?

The docker compose up command aggregates the output of each container (like docker compose logs --follow does). When the command exits, all containers are stopped. Running docker compose up --detach starts the containers in the background and leaves them running.

Does Docker compose up restart container?

The docker compose start command is useful only to restart containers that were previously created, but were stopped. It never creates new containers.


1 Answers

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.

like image 142
ThatsNinja Avatar answered Oct 29 '22 08:10

ThatsNinja