为什么 docker-compose 命令失败而 docker 运行 命令成功?
Why does this docker-compose command fail while docker run command succeeds?
我有以下 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
编辑:和以下 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
如果我 运行 docker-compose up
carton exec ...
命令失败:
$ 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
...
但是,如果我 运行 在容器上手动执行相同的命令,它会成功:
$ 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/
想知道这两个命令有什么不同吗?
供参考 carton 就像 Perl 的 Bundler。使用 carton exec
应该设置 Perl 环境,以便包括包含所有应用程序特定依赖项的适当库路径 - 与 docker run
命令一起使用。
我们可以看到正在构建的 Dockerfile 吗? (我缺乏在评论中提问的声誉。编辑:谢谢!)
(编辑:)
我注意到的一个区别是您在 docker-compose 文件中将 .
挂载到 /code
,但当 运行 命令手动。我对 Carton 并不特别熟悉,但是如果它在 /code
中创建工件,当您在 Dockerfile 中执行 carton install
时,您可能会因为 docker-编写 volumes
定义。
我有以下 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
编辑:和以下 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
如果我 运行 docker-compose up
carton exec ...
命令失败:
$ 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
...
但是,如果我 运行 在容器上手动执行相同的命令,它会成功:
$ 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/
想知道这两个命令有什么不同吗?
供参考 carton 就像 Perl 的 Bundler。使用 carton exec
应该设置 Perl 环境,以便包括包含所有应用程序特定依赖项的适当库路径 - 与 docker run
命令一起使用。
我们可以看到正在构建的 Dockerfile 吗? (我缺乏在评论中提问的声誉。编辑:谢谢!)
(编辑:)
我注意到的一个区别是您在 docker-compose 文件中将 .
挂载到 /code
,但当 运行 命令手动。我对 Carton 并不特别熟悉,但是如果它在 /code
中创建工件,当您在 Dockerfile 中执行 carton install
时,您可能会因为 docker-编写 volumes
定义。