Consul: docker-compose build error

Created on 21 Mar 2021  路  4Comments  路  Source: consul/consul

Hi there!! I'm trying to build and up a consul project with docker-compose

I have all the requisites installed
I follow all the instructions and I test it locally and consuls deploy to web and runs fine
but when build the containers on the same enviroment to run in a docker production env
get this error when execute

$ sudo docker-compose run app rake db:create
[...]
Successfully tagged consul_app:latest
consul_database_1 is up-to-date
Creating consul_app_1 ... error

**ERROR: for consul_app_1  Cannot create container for service app: create .: volume name is too short, names should be at least two alphanumeric characters

ERROR: for app  Cannot create container for service app: create .: volume name is too short, names should be at least two alphanumeric characters**
ERROR: Encountered errors while bringing up the project.
version: "3"
services:
  # service configuration for our database
  database:

    # use the preferred version of the official Postgres image
    # see https://hub.docker.com/_/postgres/
    image: postgres:9.4.5

    # persist the database between containers by storing it in a volume
    volumes:
      - docker-example-postgres:/var/lib/postgresql/data

  # service configuration for our dockerized Rails app
  app:

    # use the Dockerfile next to this file
    build: .
    entrypoint: /usr/local/bin/entrypoint.sh
    command: bundle exec rails s -p 3000 -b "0.0.0.0"
    working_dir: /var/www/consul

    # rely on the RAILS_ENV value of the host machine
    # environment:
    #RAILS_ENV: $RAILS_ENV

    # makes the app container aware of the DB container
    depends_on:
      - database

    # expose the port we configured Unicorn to bind to
    ports:
      - "3000:3000"
    # map our application source code, in full, to the application root of our container
    volumes:
      - .:/var/www/consul:delegated
      - bundle:/usr/local/bundle:delegated
      - "$SSH_AUTH_SOCK:/tmp/agent.sock"
    environment:
      - SSH_AUTH_SOCK=/tmp/agent.sock
volumes:
  docker-example-postgres: {}
  bundle: {}

This is Dockerfile

FROM ruby:2.6.6

ENV DEBIAN_FRONTEND noninteractive

# Install essential Linux packages
RUN apt-get update -qq
RUN apt-get install -y cmake build-essential libpq-dev postgresql-client nodejs ansible imagemagick sudo libxss1 libappindicator1 libindicator7 unzip memcached

# Files created inside the container repect the ownership
RUN adduser --shell /bin/bash --disabled-password --gecos "" consul \
  && adduser consul sudo \
  && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

RUN echo 'Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bundle/bin"' > /etc/sudoers.d/secure_path
RUN chmod 0440 /etc/sudoers.d/secure_path

COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh

# Define where our application will live inside the image
ENV RAILS_ROOT /var/www/consul

# Create application home. App server will need the pids dir so just create everything in one shot
RUN mkdir -p $RAILS_ROOT/tmp/pids

# Set our working directory inside the image
WORKDIR $RAILS_ROOT

# Use the Gemfiles as Docker cache markers. Always bundle before copying app src.
# (the src likely changed and we don't want to invalidate Docker's cache too early)
# http://ilikestuffblog.com/2014/01/06/how-to-skip-bundle-install-when-deploying-a-rails-app-to-docker/
COPY Gemfile Gemfile

COPY Gemfile.lock Gemfile.lock

COPY Gemfile_custom Gemfile_custom

# Prevent bundler warnings; ensure that the bundler version executed is >= that which created Gemfile.lock
RUN gem install bundler

# Finish establishing our Ruby environment
RUN bundle install --full-index

# Install Chromium for E2E integration tests
RUN apt-get update -qq && apt-get install -y chromium

# Copy the Rails application into place
COPY . .

# Define the script we want run once the container boots
# Use the "exec" form of CMD so our script shuts down gracefully on SIGTERM (i.e. `docker stop`)
# CMD [ "config/containers/app_cmd.sh" ]
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]

I try to figure out with volumes and so with all I can find online but no way
Thanks in advance

All 4 comments

Hi @vinxenxo you could give a try with our docker related files >> https://file.participation.tools/f.php?h=3L36DBL5&d=1 works smooth for us (also added the .env file voor development) Cheers,

Thanks for the files @raoulkramer , I think there's a missing script, though:

Step 10/19 : COPY scripts/tmp-cleanup.sh /usr/local/bin/tmp-cleanup.sh
COPY failed: file not found in build context or excluded by .dockerignore: stat scripts/tmp-cleanup.sh: file does not exist

And the file doesn't come in the zip

hi @glicerico , Sorry my mistake, I was testing a script but that didn't work. So please take line 20 COPY scripts/tmp-cleanup.sh /usr/local/bin/tmp-cleanup.sh out of the dockerfile.

Quoting a comment in #3588 (by @asolera ):

I had the same problem here! Solved by changing the app/volume section of docker-compose.yml file to this:

 volumes:
      - "$PWD:/var/www/consul"
Was this page helpful?
0 / 5 - 0 ratings

Related issues

PierreMesure picture PierreMesure  路  3Comments

bertocq picture bertocq  路  7Comments

decabeza picture decabeza  路  5Comments

MariaCheca picture MariaCheca  路  4Comments

decabeza picture decabeza  路  4Comments