Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to create docker image with bash script

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

I’m trying to run it but it doesn’t work.

enter image description here

The problem is that it can’t find files to copy. Maybe there is some WORKDIR required or smth else.

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 or URL. 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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading