LoginSignup
0
1

More than 1 year has passed since last update.

Dockerfileで上の階層をCOPYできん

Posted at

前提

  • docker-composeを利用している

やりたいこと

sampleディレクトリの内容をimageに入れたい

NGパターン:sob:

.
├─ docker
│   └ app
│      └ Dockerfile
├─ sample
└ docker-compose.yml
docker-compose.yml
version: '3'
services:
  app:
    container_name: 'sample_app'
    build:
      context: docker/app
      dockerfile: Dockerfile
Dockerfile
FROM php:8.0-fpm-alpine
COPY ./sample /app

これでビルドすると

$ docker-compose up --build
failed to compute cache key: "/sample" not found: not found

てっきりCOPYコマンドのpathの指定の仕方が間違っていると思っていたが、
そうではなかった。
docker-compose.ymlのcontextの指定の仕方が原因だった。

おそらくこの設定ではDockerfileはapp以下のファイルしか見れないのだろと思う。

OKパターン:blush:

.
├─ docker
│   └ app
│      └ Dockerfile
├─ sample
└ docker-compose.yml
docker-compose.yml
version: '3'
services:
  app:
    container_name: 'sample_app'
    build:
-      context: docker/app
-      dockerfile: Dockerfile
+      context: .
+      dockerfile: docker/app/Dockerfile
Dockerfile
FROM php:8.0-fpm-alpine
COPY ./sample /app

contextを上の階層にしてやることでDockerfileからも
上の階層を参照できるようになる。(ということだと認識している)

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1