Reputation: 2754
I have a rails application that runs on Docker. My source code have the following files:
Dockerfile
FROM ruby:2.6.0
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp
CMD bash -c "rm -f tmp/pids/server.pid && rails s -p 3000 -b '0.0.0.0'"
docker-compose.yml
version: '3'
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
ports:
- "5432:5432"
redis:
image: redis
command: redis-server
ports:
- "6379:6379"
sidekiq:
build: .
command: bundle exec sidekiq
depends_on:
- redis
volumes:
- .:/myapp
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
- redis
- sidekiq
It runs normally using docker-compose up
since I'm running this with the source code level.
Now when I build this app and push it to Dockerhub
docker build -t myusername/rails-app .
docker push myusername/rails-app
I'm expecting that I can run the rails app from an independent docker-compose.yml
separately from the source code.
version: '3'
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
ports:
- "5432:5432"
redis:
image: redis
command: redis-server
ports:
- "6379:6379"
sidekiq:
build: .
command: bundle exec sidekiq
depends_on:
- redis
volumes:
- .:/myapp
web:
image: myusername/rails-app:latest # <= Running the app now from the image
command: bash -c "rm -f tmp/pids/server.pid && rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
- redis
- sidekiq
The only containers running are redis
and db
. The web
is looking for this
Could not locate Gemfile or .bundle/ directory
Upvotes: 0
Views: 334
Reputation: 3026
In the second docker-compose.yml
file, the one that should work somewhere else without the source code, you're still having the volume mounting the local folder in the container:
volumes:
- .:/myapp
Remove that from the sidekiq
and web
containers and it should work.
You've also kept the build: .
for the sidekiq
container which is useful only for the development box. Replace it with the image
attribute, pointing to your image.
To summarise your docker-comspose.yaml
file:
version: '3'
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
ports:
- "5432:5432"
redis:
image: redis
command: redis-server
ports:
- "6379:6379"
sidekiq:
image: myusername/rails-app:latest
command: bundle exec sidekiq
depends_on:
- redis
web:
image: myusername/rails-app:latest # <= Running the app now from the image
command: bash -c "rm -f tmp/pids/server.pid && rails s -p 3000 -b '0.0.0.0'"
ports:
- "3000:3000"
depends_on:
- db
- redis
- sidekiq
Upvotes: 2