How to download and unzip in Dockerfile

DromiX picture DromiX · Dec 18, 2018 · Viewed 10.6k times · Source

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;

Answer

Taron Saribekyan picture Taron Saribekyan · Feb 7, 2020

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