1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Dockerfileで親ディレクトリにあるファイルを参照できない問題

1
Posted at

現象

├── nginx
|   └── Dockerfile
├── statics
├── Dockerfile
└── docker-compose.yaml

Dockerfileから親ディレクトリにあるファイルを参照しようとしてもできませんでした。

nginx/Dockerfile
FROM nginx
ADD ../statics /var/www/
CMD ["nginx", "-g", "daemon off;", "-c", "/etc/nginx/nginx.conf"]
$ docker-compose up --build
Building nginx
Step 1/4 : FROM nginx
 ---> be1f31be9a87
Step 2/4 : ADD statics /var/www/
ERROR: Service 'nginx' failed to build: ADD failed: stat /var/lib/docker/tmp/docker-builder740600385/statics: no such file or directory

ADDで失敗してしまいます。

解決

docker-compose.yamlでcontextを親ディレクトリを含むようにすることで、ファイルを参照できるようになりました。

docker-compose.yaml
version: '3'
services:
  nginx:
#    build: ./nginx
    build: 
      context: .
      dockerfile: ./nginx/Dockerfile
    container_name: proxy
    ports:
      - 80:80
  api:
    build: .
nginx/Dockerfile
FROM nginx
# ADD ../statics /var/www/
ADD statics /var/www/
CMD ["nginx", "-g", "daemon off;", "-c", "/etc/nginx/nginx.conf"]
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?