Can we build a docker image using .tar or zip archive

Abdul Rehman picture Abdul Rehman · Jul 26, 2017 · Viewed 8.6k times · Source

Can we build a docker image using tarball or zip archive which includes dockerfile inside that. I need to build a image from archives by using docker api.

Is there any reference or resource , I have search for 3o minutes but couldn't find anything.

Help me, please! Thanks in advance!

Answer

souparno majumder picture souparno majumder · Jan 19, 2019

yes a dockerimage can be build from a tarball containing the Dockerfile. Let's assume we have a dockerfile called myDockerfile which contains the following scripts

FROM ubuntu

COPY ./venv /

CMD ["/bin/bash"]

myDockerFile is present inside the folder dockerfiles

FOLDER --> dockerfiles
FILE   -----------> myDockerFile 

the tarball for folder dockerfiles is called dockerfiles.tar

the docker command to build the image will be:-

cat dockerfiles.tar | docker build - -f dockerfiles/myDockerFile -t mydockerimage

note:-

-f denotes the docker file in context to the tarball , if the dockerfile is called 'Dockerfile'
then there is no need to mention the name of the filename verbose