How to set different context for docker-compose and DockerFile [duplicate]
Answer a question
What I'm trying to do:
I'm planning to create a build folder in my service repo, which should contain all docker-related files.
My service depends on postgres and rabbitmq, so as dev workflow I'm starting the service dependencies as docker contains and run my application by connecting to ports exposed by the containers.
My service already has SQL files needed to create DB, create tables, and create index under the deploy-scripts folder. ( please refer to the folder structure image attached below )
I'm planning to spin up a docker container with all tables, DB, and roles required by copying the deploy-scripts folder to docker-entry point script as mentioned in this link How to create User/Database in script for Docker Postgres
Details:
Docker Compose File
version: '3.4'
services:
database:
build:
context: ./postgres
dockerfile: DockerFile
ports:
- 5432:5432
volumes:
- database-data:/var/lib/postgresql/data
volumes:
database-data:
Postgres Docker File
FROM postgres:10.17-buster
COPY ../deploy-scripts /docker-entrypoint-initdb.d/
This is my folder structure. 
When I execute the docker-compose -f build/docker-compose.dev.yml up command I'm getting the below error
Building database
[+] Building 0.2s (6/6) FINISHED
=> [internal] load build definition from DockerFile 0.0s
=> => transferring dockerfile: 36B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/postgres:10.17-buster 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 2B 0.0s
=> CACHED [1/2] FROM docker.io/library/postgres:10.17-buster 0.0s
=> ERROR [2/2] COPY ../deploy-scripts /docker-entrypoint-initdb.d/ 0.0s
------
> [2/2] COPY ../deploy-scripts /docker-entrypoint-initdb.d/:
------
failed to compute cache key: "/deploy-scripts" not found: not found
ERROR: Service 'database' failed to build: Build failed
Can any of you help me out? How to copy the deploy-scripts folder to postgres ?
Docker Compose has to use build folder context? Does Docker File have to use my service root folder context?
Answers
I think the error is related to the location of your deploy-scripts directory. You attempt to perform a copy from the parent folder and this is not possible.
The
<src>path must be inside the context of the build; you cannotCOPY ../something /something, because the first step of adocker buildis to send the context directory (and subdirectories) to the docker daemon. src
It must be in a sub-directory of the directory containing your Dockerfile.
更多推荐
所有评论(0)