前提
SPA構成でポートフォリオ作成をしています。
api (rails7), nginx, db (postgres)のDocker環境は作成済みで、Railsアプリの開発を進めており、そこにclient (React)環境を追加しようとDockerfileを作成し、docker-compose.ymlにも設定を追加しました。
docker-compose logで確認したところ、エラーは発生しておりません。また、clientのコンテナに入り、node -vを確認したところ、v18.12.1と正常にバージョンが表示されております。
ファイル構成と内容は以下のようになっております。
Sample_app ├── api │ ├── Dockerfile │ └── その他Railsアプリファイル等 ├── client/ (ここを追加) │ └── Dockerfile (ここを追加) ├── nginx/ │ └── nginxファイル等 ├── docker-compose.yml └── その他ファイル
client/Dockerfile
FROM node:18.12.1 WORKDIR /usr/src/app
docker-compose.yml
version: "3.9" services: db: image: postgres:15.1 volumes: - db_1:/var/lib/postgresql/data environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} api: build: context: ./api dockerfile: Dockerfile command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" ports: - "3000:3000" volumes: - ./api:/myapp - ./nginx:/myapp/nginx environment: DATABASE_PASSWORD: ${DATABASE_PASSWORD} tty: true stdin_open: true depends_on: - db nginx: image: nginx:1.23.2 ports: - "80:80" command: [nginx-debug, '-g', 'daemon off;'] volumes: - ./nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf - ./nginx/html/swagger-ui:/usr/share/nginx/html/swagger-ui depends_on: - api client: build: context: ./client dockerfile: Dockerfile ports: - "3001:3001" volumes: - ./client:/usr/src/app tty: true stdin_open: true volumes: db_1:
実現したいこと
/clientにあるファイル・ディレクトリをclientコンテナ内のusr/src/appにバインドマウントしたいです。
エラーメッセージ
なし
試したこと
- 別の新規のディレクトリを作成し、以下のようなフォルダ構成でclinetのみ環境構築した結果、バインドマウントできました
Another_sample_app ├── client/ │ └── Dockerfile └── docker-compose.yml
client/Dockerfile
FROM node:18.12.1 WORKDIR /usr/src/app
docker-compose.yml
version: "3.9" services: client: build: context: ./client dockerfile: Dockerfile ports: - "3001:3001" volumes: - ./client:/usr/src/app tty: true stdin_open: true
- 上記の結果より、可能性は低そうでうすがclientの順番が問題かと思い、元のアプリのdocker-compose.ymlの記述を以下のように入れ替え、clientを一番上に持ってきたが、正常にバインドマウントできませんでした
version: "3.9" services: client: build: context: ./client dockerfile: Dockerfile ports: - "3001:3001" volumes: - ./client:/usr/src/app tty: true stdin_open: true db: image: postgres:15.1 volumes: - db_1:/var/lib/postgresql/data environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} api: build: context: ./api dockerfile: Dockerfile command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" ports: - "3000:3000" volumes: - ./api:/myapp - ./nginx:/myapp/nginx environment: DATABASE_PASSWORD: ${DATABASE_PASSWORD} tty: true stdin_open: true depends_on: - db nginx: image: nginx:1.23.2 ports: - "80:80" command: [nginx-debug, '-g', 'daemon off;'] volumes: - ./nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf - ./nginx/html/swagger-ui:/usr/share/nginx/html/swagger-ui depends_on: - api volumes: db_1:
- volumesの記法を下記のようにshort syntaxからlong syntaxに変更したが同様にエラーは発生せず、バインドマウントできませんでした
version: "3.9" services: db: image: postgres:15.1 volumes: - db_1:/var/lib/postgresql/data environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} api: build: context: ./api dockerfile: Dockerfile command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" ports: - "3000:3000" volumes: - ./api:/myapp - ./nginx:/myapp/nginx environment: DATABASE_PASSWORD: ${DATABASE_PASSWORD} tty: true stdin_open: true depends_on: - db nginx: image: nginx:1.23.2 ports: - "80:80" command: [nginx-debug, '-g', 'daemon off;'] volumes: - ./nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf - ./nginx/html/swagger-ui:/usr/share/nginx/html/swagger-ui depends_on: - api client: build: context: ./client dockerfile: Dockerfile ports: - "3001:3001" volumes: - type: bind source: "./client" target: "/usr/src/app" tty: true stdin_open: true volumes: db_1:
- 一度全てのimagesを削除し、再度ビルドしたが同様にバインドマウントできませんでした
補足情報(FW/ツールのバージョンなど)
OS: macOS Big Sur Version 11.4 (intel processor)
Docker: Docker version 20.10.21
docker-compose: Docker Compose version v2.13.0
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。