我正在为Ruby on Rails项目构建docker容器,但构建完成后,在本地计算机中请求所有资产并在生产服务器中请求404(未找到)时,所有资产返回405(不允许)。
发展:
生产:
我已经重新安装了docker,但是得到了相同的结果。
更新:
这是我的dockerfile:
FROM ruby:2.5.1-alpine3.7
RUN apk add --update build-base nodejs tzdata libxml2-dev postgresql-dev postgresql-client git less
RUN apk --update add --virtual build-dependencies make g++
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install --binstubs
RUN apk del build-dependencies && rm -rf /var/cache/apk/*
COPY . ./
这是我的docker-composer:
version: '3'
services:
setup:
image: minecraft.grumpyzombies.com/pcz-store
volumes:
- /root/apps/pcz-store/uploads:/myapp/public/uploads
- /root/apps/pcz-store/assets:/myapp/public/assets
depends_on:
- db
environment:
- RAILS_ENV=production
- SECRET_KEY_BASE=b84b5c15aa42b2be2290d4bb330e3ce4ec0d39847babca3c6189f1721e7bc636bd60d7d7cc0fb156d4845f403dfa5432448435926b79c913133bbf75d1cd498e
restart: on-failure
command: docker/assets_precompile.sh
db:
image: postgres:10
volumes:
- /root/apps/pcz-store/db:/var/lib/postgresql/data
web:
image: minecraft.grumpyzombies.com/pcz-store
volumes:
- /root/apps/pcz-store/uploads:/myapp/public/uploads
- /root/apps/pcz-store/assets:/myapp/public/assets
depends_on:
- setup
- db
environment:
- RAILS_ENV=production
- ELASTICSEARCH_URL=http://elasticsearch:9200
- SECRET_KEY_BASE=b84b5c15aa42b2be2290d4bb330e3ce4ec0d39847babca3c6189f1721e7bc636bd60d7d7cc0fb156d4845f403dfa5432448435926b79c913133bbf75d1cd498e
command: docker/entrypoint.sh
nginx:
build:
context: .
dockerfile: Dockerfile-nginx
image: minecraft.grumpyzombies.com/pcznginx
restart: on-failure
ports:
- '80:80'
- '443:443'
depends_on:
- web
volumes:
- /root/apps/pcz-store/assets:/var/www/myapp/public/assets
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.0
container_name: elasticsearch
restart: on-failure
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
environment:
- node.name=es01
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
nproc: 65535
memlock:
soft: -1
hard: -1
cap_add:
- ALL
privileged: true
deploy:
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
ports:
- '9200:9200'
- '9300:9300'
command: su -c ./bin/elasticsearch elasticsearch
depends_on:
- web
- db
第二次更新:
这是我在nginx容器中运行ls -lart /var/www/myapp/public/assets
所得到的。
root@pcz-store:~# docker exec -it d47aecf71c05 sh
/var/www/myapp # ls -lart /var/www/myapp/public/assets
total 3624
-rw-r--r-- 1 root root 6760 Feb 28 21:59 terms_conditions_icon-34d7728acea9739e5663475fa58bb00070eada9dbf035f396ffa9ebf9d61a695.png
-rw-r--r-- 1 root root 7717 Feb 28 21:59 shipping_icon-9c050291621972a805212663d85d85ce16f4ab4bac1b6df26fb4c81111b04954.png
-rw-r--r-- 1 root root 2194 Feb 28 21:59 search_btn-1337ebd34122bf832ef77c294a9a0cfacc01eec14abacd672760d4534f66309f.png
-rw-r--r-- 1 root root 6323 Feb 28 21:59 pcz_small_logo-f2cc1d44bb90b448b9b88348664a8384b378a257ab2c0bf8b0a3858f6a68150d.png
-rw-r--r-- 1 root root 2336 Feb 28 21:59 filter_menu-32653a4203b8bf0d5de68691de26f9c0b590018b5d8c34e8108dff55ca0a8f28.png
-rw-r--r-- 1 root root 1090 Feb 28 21:59 card_with_items-14c488398004329490b11e22dd425126e726bb724d8997482011fb8d53681d10.png
-rw-r--r-- 1 root root 5494 Feb 28 21:59 card_payment_icon-506681ad792fbceb514fe8dcb48c48b1ad552c1a430bb83cb8fd0a72bbfeed6f.png
-rw-r--r-- 1 root root 771 Feb 28 21:59 card-8ac603143bafe864976639270b0e7218a40c4fc7d7bb14d8d1eaa0f4b5a96e14.png
-rw-r--r-- 1 root root 6338 May 6 21:57 pcz_logo_blue-df8681f5d301079d4b14a0f5f61a64015fa3005e665fcb6d6efac10d541bfba9.png
-rw-r--r-- 1 root root 7494 May 6 21:57 pcz_logo_2-f65fe6b96c6cb86a5546e2c96db79db837b97c9ebe2ac80a928ca30604890709.png
-rw-r--r-- 1 root root 6009 May 6 21:57 pcz_logo-30a5ea591292bd780af89c4070b9f0e9bee3feccee260e8767611f88d3129813.png
-rw-r--r-- 1 root root 4143 May 6 21:57 menu_icon-63b742c78ceea89533f5e47f71cf7694a7603f182618b8b91b2f2e8c9f5cad88.png
-rw-r--r-- 1 root root 1975 May 6 21:57 card_white_with_items-a27394bbc2b5b6687aaad72dc2ae1caadbac4670e91f644fb6bf179da664a41e.png
-rw-r--r-- 1 root root 1834 May 6 21:57 card_white-29b18b65b693a5470c4dc25503c7817e9ee655d0a92b5fced902dcdcde038c72.png
drwxr-xr-x 3 root root 4096 May 8 17:31 ..
-rw-r--r-- 1 root root 85634 May 9 18:30 login_background-db8d4fb738db92fa96201ae66011a35566030de51a44b3ffbd47d5f5b07d5614.jpg
-rw-r--r-- 1 root root 91419 May 9 18:30 admin-b99dedd500b2b0074741175197a8f478fa8efec08effdc1ae28ecc5c16c81460.css.gz
-rw-r--r-- 1 root root 575024 May 9 18:30 admin-b99dedd500b2b0074741175197a8f478fa8efec08effdc1ae28ecc5c16c81460.css
-rw-r--r-- 1 root root 98024 May 9 18:33 fontawesome-webfont-ba0c59deb5450f5cb41b3f93609ee2d0d995415877ddfa223e8a8a7533474f07.woff
-rw-r--r-- 1 root root 134485 May 9 18:33 fontawesome-webfont-ad6157926c1622ba4e1d03d478f1541368524bfc46f51e42fe0d945f7ef323e4.svg.gz
-rw-r--r-- 1 root root 444379 May 9 18:33 fontawesome-webfont-ad6157926c1622ba4e1d03d478f1541368524bfc46f51e42fe0d945f7ef323e4.svg
-rw-r--r-- 1 root root 98106 May 9 18:33 fontawesome-webfont-aa58f33f239a0fb02f5c7a6c45c043d7a9ac9a093335806694ecd6d4edc0d6a8.ttf.gz
-rw-r--r-- 1 root root 165548 May 9 18:33 fontawesome-webfont-aa58f33f239a0fb02f5c7a6c45c043d7a9ac9a093335806694ecd6d4edc0d6a8.ttf
-rw-r--r-- 1 root root 98200 May 9 18:33 fontawesome-webfont-7bfcab6db99d5cfbf1705ca0536ddc78585432cc5fa41bbd7ad0f009033b2979.eot.gz
-rw-r--r-- 1 root root 165742 May 9 18:33 fontawesome-webfont-7bfcab6db99d5cfbf1705ca0536ddc78585432cc5fa41bbd7ad0f009033b2979.eot
-rw-r--r-- 1 root root 77160 May 9 18:33 fontawesome-webfont-2adefcbc041e7d18fcf2d417879dc5a09997aa64d675b7a3c4b6ce33da13f3fe.woff2
-rw-r--r-- 1 root root 34260 May 9 18:33 application-ff019001d3b7f91bae6da2b446df296fa8f0b1e8d236c5de4449aa65f683f644.css.gz
-rw-r--r-- 1 root root 199990 May 9 18:33 application-ff019001d3b7f91bae6da2b446df296fa8f0b1e8d236c5de4449aa65f683f644.css
-rw-r--r-- 1 root root 69867 May 9 18:33 application-9fb13c3411be138ab44f1c4ab79a3325374cb7bdc733423b1d0930a4051030d3.js.gz
-rw-r--r-- 1 root root 235590 May 9 18:33 application-9fb13c3411be138ab44f1c4ab79a3325374cb7bdc733423b1d0930a4051030d3.js
-rw-r--r-- 1 root root 212342 May 9 18:33 admin-66de62e1b8d9a65dfa06311ddcf46d9b39d8ea9c52989f89886ed8a036077d75.js.gz
-rw-r--r-- 1 root root 768369 May 9 18:33 admin-66de62e1b8d9a65dfa06311ddcf46d9b39d8ea9c52989f89886ed8a036077d75.js
drwxr-xr-x 3 root root 4096 May 13 03:27 img
drwxr-xr-x 2 root root 4096 May 13 03:27 font-awesome
-rw-r--r-- 1 root root 21847 May 13 03:27 .sprockets-manifest-757ca632d463d59749404f32eb6c13db.json
drwxr-xr-x 4 root root 4096 May 13 03:27 .