Error when add an additional volume for the Ruby on Rails web app container
Hello, I'm programmming a containerized Rails app. Right now I'm doing the setup for the production environment.
My docker-compose.production.yml
:
version: '3'
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 puma -C config/puma.rb"
volumes:
- .:/rails-lyrics-site
- /rails-lyrics-site/node_modules
- bundle:/usr/local/bundle
- public-data:/rails-lyrics-site/public
- log-data:/rails-lyrics-site/log
- tmp-data:/rails-lyrics-site/tmp
ports:
- "3000:3000"
depends_on:
- db
nginx:
build:
context: containers/nginx
volumes:
- public-data:/rails-lyrics-site/public
- tmp-data:/rails-lyrics-site/tmp
ports:
- "80:80"
depends_on:
- web
volumes:
bundle:
public-data:
log-data:
tmp-data:
The problem is when I start with docker-compose -f docker-compose.production.yml up
, I got the error:
The problems will not occur when I remove the tmp-data
volume from the web container. It seems that with this config, my tmp folder in the Rails source code is not being written into
Can anyone help me, please?
OK, my problems were I didn't public the volume in Dockerfile
# Dockerfile
FROM ruby:3.1.2
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -\
&& echo 'deb http://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get update -qq && apt-get install -y nodejs build-essential postgresql-client yarn \
curl dirmngr apt-transport-https lsb-release ca-certificates
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN bundle install
COPY . /app
RUN mkdir -p tmp/sockets
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
VOLUME /app/public
VOLUME /app/tmp
CMD bash -c "rm -f tmp/pids/server.pid && bundle exec puma -C config/puma/production.rb"
EXPOSE 3000
After adding
VOLUME /app/public
VOLUME /app/tmp
The above docker compose worked