I think I have a bit of a hard time understanding what files do I need to be able to run a container with my Rails app on an empty instance.
I have a docker-compose.prod.yml
that I want to run:
version: "3.8"
services:
db:
image: postgres
environment:
POSTGRES_USER: ${POSTGRES_USER:-default}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-default}
volumes:
- ./tmp/db:/var/lib/postgresql/data
app:
image: "username/repo:${WEB_TAG:-latest}"
depends_on:
- db
command: bash -c "rm -f tmp/pids/server.pid && bundle exec puma -C config/puma.rb"
volumes:
- .:/myapp
- public-data:/myapp/public
- tmp-data:/myapp/tmp
- log-data:/myapp/log
environment:
POSTGRES_USER: ${POSTGRES_USER:-default}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-default}
POSTGRES_HOST: ${POSTGRES_HOST:-default}
web:
build: nginx
volumes:
- public-data:/myapp/public
- tmp-data:/myapp/tmp
ports:
- "80:80"
depends_on:
- app
volumes:
public-data:
tmp-data:
log-data:
db-data:
So, in the instance, I have the docker-compose.prod.yml
file. And since I am passing variables for the environments and the image web tag, I created an .env
file with those variables in it as well. Finally, since I am building nginx
, I have a folder with the image:
FROM arm64v8/nginx
# インクルード用のディレクトリ内を削除
RUN rm -f /etc/nginx/conf.d/*
# Nginxの設定ファイルをコンテナにコピー
ADD nginx.conf /etc/nginx/myapp.conf
# ビルド完了後にNginxを起動
CMD /usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/myapp.conf
and config file nginx.conf
user root;
worker_processes 1;
events{
worker_connections 512;
}
# ソケット接続
http {
upstream myapp{
server unix:///myapp/tmp/sockets/puma.sock;
}
server { # simple load balancing
listen 80;
server_name localhost;
#ログを記録しようとするとエラーが生じます
#root /myapp/public;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
proxy_pass http://myapp;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
}
}
So, docker-compose.prod.yml
, nginx
directory with the 2 files and the .env
file.
When I do: docker-compose -f docker-compose.prod.yml --env-file .env run app rake db:create db:migrate
it downloads the postgres
and app
images but once it starts doing the rake
for the db:create db:migrate
, I get this error:
Status: Downloaded newer image for user/repo:48
Creating rails-app_db_1 ... done
Creating rails-app_app_run ... done
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/usr/local/bundle/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)
but then when I add the Rakefile
, it keeps asking for other dependents files so either I need the whole project itself (clone it from my repo on GitHub) or I am doing this wrong.
Any ideas on what files do I need or if I need to change commands are welcome! Thank you.