【发布时间】:2019-05-10 00:22:31
【问题描述】:
我有一个 docker-compose.yml 文件和一个 Dockerfile。我添加了一个绑定安装。如果我不尝试编译或运行任何混合命令并让 docker-compose “启动”并进入交互式 shell。我实际上可以看到“绑定”卷和所有文件。
问题是当我尝试 cd 或 RUN 该目录中的命令时 - 就好像它不存在并且“返回退出代码为 1”错误
docker-compose.yml
# Version of docker-compose
version: '3.7'
# Containers we are going to run
services:
# Our Phoenix container
phoenix:
# The build parameters for this container.
build:
# Here we define that it should build from the current directory
context: .
environment:
# Variables to connect to our Postgres server
PGUSER: gametime_dev
PGPASSWORD: gametime-dev
PGDATABASE: gametime_dev
PGPORT: 5432
# Hostname of our Postgres container
PGHOST: db
ports:
# Mapping the port to make the Phoenix app accessible outside of the container
- "4000:4000"
depends_on:
# The db container needs to be started before we start this container
- db
- redis
volumes:
- type: bind
source: .
target: /opt/gametime
redis:
image: "redis:alpine"
ports:
- "6379:6379"
sysctls:
net.core.somaxconn: 1024
db:
# We use the predefined Postgres image
image: kartoza/postgis:11.0-2.5
environment:
# Set user/password for Postgres
POSTGRES_USER: gametime_dev
POSTGRES_PASS: gametime-dev
# Set a path where Postgres should store the data
PGDATA: /var/lib/postgresql/data/pgdata
restart: always
volumes:
- pgdata:/usr/local/var/postgres_data
# Define the volumes
volumes:
pgdata:
Dockerfile:
# Latest version of Erlang-based Elixir installation: https://hub.docker.com/_/elixir/
FROM bitwalker/alpine-elixir-phoenix as build
RUN apk update && \
apk add postgresql-client
# Create and set home directory
ENV HOME /opt/gametime WORKDIR $HOME
# Configure required environment
ENV MIX_ENV dev # Set and expose PORT environmental variable
ENV PORT ${PORT:-4000}
EXPOSE $PORT
VOLUME /opt/gametime
# Install hex (Elixir package manager)
RUN mix local.hex --force
# Install rebar (Erlang build tool) RUN mix local.rebar --force
# Copy all dependencies files
# not commenting this out defeats the purpose of needing the volume
# COPY mix.* ./
# Install all production dependencies RUN mix deps.get --only dev
# Compile all dependencies
#THIS FAILS - BECAUSE IT CAN'T FIND THE mix.exs file
RUN mix deps.compile
# Copy all application files # COPY . .
# Compile the entire project
RUN mix compile
# IF I COMMENT OUT THE ABOVE THIS ALSO FAILS BECAUSE IT CAN'T FIND ASSETS DIRECTORY
RUN cd assets && npm install
CMD ["./entrypoint.sh"]
错误:
Step 11/15 : RUN mix deps.get --only dev
---> Running in 831e2e0d3fe2
** (Mix) Could not find a Mix.Project, please ensure you are running
Mix in a directory with a mix.exs file
ERROR: Service 'phoenix' failed to build: The command '/bin/sh -c mix
deps.get --only dev' returned a non-zero code: 1
我想要做的是共享应用程序目录并使用容器中的 elixir/erlang/OTP 库来构建和运行该代码。这样我就有了一个开发环境,并且我所做的任何更改基本上都保存在我的本地机器上。
公平起见,我可以从 github 中提取数据 - 然后在杀死我的容器之前提交更改。但我想先试试这个。
[更新]:所以我发现如果我在 entrypoiont.sh 文件中运行混合命令,一切都会正常工作。我不知道为什么 Dockerfile 中没有该卷,因此没有回答我自己的问题。我从here 得到了线索。
我想这样做的原因 - 是将 deps.get 和 deps.compile 步骤缓存为一个层,这样我就不必每次运行 docker-compose up 时都这样做
【问题讨论】:
标签: docker-compose elixir dockerfile phoenix-framework