6

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!

Abdul Rehman
  • 5,326
  • 9
  • 77
  • 150

3 Answers3

3

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
isnvi23h4
  • 1,910
  • 1
  • 27
  • 45
1

You can use docker load command to get more information visit

vegiops
  • 293
  • 2
  • 6
0

Do you mean, that your tar.gz is containing a Dockerfile and you would like to build the image of it? As it is if you download a archive from a github release, for example: https://github.com/nginxinc/docker-nginx/releases?

Yes you can:

#!/bin/bash
wget "https://github.com/nginxinc/docker-nginx/archive/1.13.2.tar.gz"
tar xvf 1.13.2.tar.gz --strip-components 3 docker-nginx-1.13.2/stable/alpine/Dockerfile && docker build . -t mynginx
m4r10k
  • 1,087
  • 8
  • 8
  • actually I was trying to build docker image using a tar which uploads by user on my django app and include dockerfile, bu it return `invalid tar header` error. – Abdul Rehman Jul 27 '17 at 04:20