Systemd-coredump taking ownership of /tmp/db directory and contents in Rails app

I have set up a containerized Rails application according to the Quickstart guide here:

https://docs.docker.com/compose/rails/

It mostly works, but requires me to sudo chown -R $USER:$USER the /tmp/db directory every time I start and stop it, because the ownership on /tmp/db changes when docker-compose up is run. At that point the permissions look like:

drwx------ 19 systemd-coredump mygroup 4096 May 4 19:37 db/

Is this expected behavior? If not, how to I stop it?

Dockerfile:

FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN gem install bundler
RUN bundle install
COPY . /myapp


COPY entrypoint.sh /usr/bin
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT [ "entrypoint.sh" ]
EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]

docker-compose.yml:

version: "3.7"
services: 
    db:
        image: postgres
        volumes: 
            - ./tmp/db:/var/lib/postgresql/data
        environment: 
            - POSTGRES_PASSWORD=<password>
    web:
        build: .
        command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
        volumes:
            - .:/myapp
        ports:
            - "3000:3000"
        depends_on: 
            - db
1 Like

You may able to work around the problem in the following ways:

Add these lines to ~/.bashrc:

export UID=$(id -u)
export GID=$(id -g)

Reload your shell:

$ source ~/.bashrc

Modify your docker-compose.yml as follows:

version: "3.7"
services:
  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
    user: "${UID}:${GID}"
    ...