Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download and unzip in Dockerfile

So, I have, it works, but I want to change the way to immediately download the file and unpack it:

Dockerfile
FROM wordpress:fpm

# Copying themes from local  
COPY  ./wordpress/ /var/www/html/wp-content/themes/wordpress/    
RUN chmod -R 777 /var/www/html/    

How can I immediately download the file from the site and unzip it to the appropriate folder?

docker-compose.yml
wordpress:
build: . 
links:
  - db:mysql
nginx:
image: raulr/nginx-wordpress 
links:
  - wordpress
ports:
 - "8080:80"
 volumes_from:
 - wordpress
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: qwerty 

I tried:

#install unzip and wget
RUN \
apt-get update && \
apt-get install unzip wget -y && \
rm -rf /var/lib/apt/lists/*

RUN wget -O /var/www/html/type.zip http://wp-templates.ru/download/2405 \
&& unzip '/var/www/html/type.zip' -d /var/www/html/wp-content/themes/ && rm 
/var/www/html/type.zip || true;
like image 596
DromiX Avatar asked Dec 18 '18 20:12

DromiX


People also ask

How do I unzip a docker file?

If the file comes from the build machine and you can change it, repack it as tar. gz and use ADD myfile. tar. gz /some/folder and Docker will automatically unpack it there.

Which docker command is used to unzip a portable docker tar?

Docker save and load: you use the commands docker save and docker load to pack/unpack the entire image in a compressed tar file.


1 Answers

Dockerfile has "native command" for copying and extracting .tar.gz files.

So you can change archive type from .zip to .tar.gz (maybe in future versions zip also will be supported, I'm not sure) and use ADD instead of COPY.

Read more about ADD

like image 107
Taron Saribekyan Avatar answered Oct 06 '22 13:10

Taron Saribekyan