Search code examples
dockergrailsdocker-compose

Grails App running in Docker Container not using Local Packages


I'm currently trying to run our app that's in Grails 2.3.11 through docker-compose with the database. I have the database up and running without issue, and also the app container sets up grails and starts the compilation process, but it goes on to downloading all the packages every time I stop and restart the package. This becomes an issue because we have to download so many packages (And there's a bunch of errors we have to work around because Grails 2). I've tried to mount my local grails folders into the container to have it run off of those but it seems to not be having any success. Is there something obvious I'm doing wrong, or some way I can easily check where the issue might be?

I'm also attempting to map all local database information into the mysql container with issue. But I haven't looked into it much yet, if you see an obvious issue there that would be helpful.

docker-compose.yml:

version: '2'
services:
  grails:
    image: ibbrussell/grails:2.3.11
    command: run-app
    volumes:
      - ~/.m2:/home/developer/.m2
      - ~/.gradle:/home/developer/.gradle
      - ~/.grails:/home/developer/.grails
      - ./:/app
    ports:
      - "8080:8080" #Grails default port
      - "5005:5005" #Grails debug port
    links:
      - db
    deploy:
      resources:
        limits:
          memory: 4G
        reservations:
          memory: 4G
  db:
    image: mysql:5.6
    container_name: grails_mysql
    ports:
      - "3306:3306"
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: 1
      MYSQL_DATABASE: grails
    volumes:
      - "/usr/local/mysql/data:/var/lib/mysql"

Dockerfile:

FROM java:8

# Set customizable env vars defaults.
ENV GRAILS_VERSION 2.3.11

# Install Grails
WORKDIR /usr/lib/jvm
RUN wget https://github.com/grails/grails-core/releases/download/v$GRAILS_VERSION/grails-$GRAILS_VERSION.zip && \
    unzip grails-$GRAILS_VERSION.zip && \
    rm -rf grails-$GRAILS_VERSION.zip && \
    ln -s grails-$GRAILS_VERSION grails

# Setup Grails path.
ENV GRAILS_HOME /usr/lib/jvm/grails
ENV PATH $GRAILS_HOME/bin:$PATH
ENV GRAILS_OPTS="-XX:MaxPermSize=4g -Xms4g -Xmx4g"

# Create App Directory
RUN mkdir /app

# Set Workdir
WORKDIR /app

# Set Default Behavior
ENTRYPOINT ["grails"]

Solution

  • So the mapping I was using ended up not being correct. I was going off a file mapping from 1 article and ended up working after trying another working mapping. I made the switch below:

    original:

    volumes:
          - ~/.m2:/home/developer/.m2
          - ~/.gradle:/home/developer/.gradle
          - ~/.grails:/home/developer/.grails
          - ./:/app
    

    new:

    volumes:
          - ~/.m2:/root/.m2
          - ~/.gradle:/root/.gradle
          - ~/.grails:/root/.grails
          - ./:/app