Issue
I want to create docker images using next script
docker build - < $2 -t $1
the first parameter is the image name, second is the path to Dockerfile.
I have the next file structure for it.
I'm getting error on COPY method
No such file or directory
Dockerfile
FROM postgres
WORKDIR ./bacisImage
ENV POSTGRES_DB pointer
ENV POSTGRES_PASSWORD pointer
ENV POSTGRES_DB 123
COPY migrations/tables/* /docker-entrypoint-initdb.d/
COPY migrations/procedures/* /docker-entrypoint-initdb.d/
Solution
rather than the path to a Dockerfile, use either basicImage
or dataImage
-- the directories which hold the Dockerfiles.
and modify your script to use the path
# ...
docker build -t $1 $2
# ...
from the docker-build docs the syntax for the build command is
$ docker build [OPTIONS] PATH | URL | -
PATH
here is what provides the build command its context
A build’s context is the set of files located in the specified
PATH
orURL
. The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.
what you pass via -
(stdin) is the Dockerfile, which only provides the instructions. with PATH
being absent, the default context is ./
so the Dockerfile is trying to copy migrations/tables
. but the context of ./
has only basicImage
and dataImage
; hence the COPY fails.
if instead you pass the PATH
of basicImage
, that is the new context. and the file Dockerfile within the context is used for building the image and everything would work as expected
Answered By - kevinnls Answer Checked By - Mildred Charles (WPSolving Admin)