Docker Community Forums

Share and learn in the Docker community.

Dockerfile - falied in download file and extract

Hello guys.

I need my Dockerfile file to download a file and extract it in the “/var/www/html” directory of the container. I tried in several ways and failed. Apparently this happens but then it seems that everything is excluded. I’ve tried with the command RUN wget , RUN curl , ADD, etc. I wanted you to get the file on the internet and extract it, that’s all. I found some examples on the internet but my code has some error that I did not identify. Below are the 2 files (Dockerfile and docker-compose.yml) that I am using to do this. I just put wordpress as an example.

file: Dockerfile

FROM php:7.4-apache
RUN apt-get update -y && \
    apt-get install -y \
	libzip-dev \
	libpng-dev \
	libc-client-dev \
	libkrb5-dev --no-install-recommends \
    wget ca-certificates
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \
    docker-php-ext-install -j$(nproc) imap

RUN docker-php-ext-install mysqli gd zip
RUN a2enmod rewrite

#COPY www/ /var/www/html/
#RUN chown -R www-data:www-data /var/www/html/
#RUN chmod -R 755 /var/www/html/

#RUN curl -o wordpress.tar.gz; \
#	tar -xzf wordpress.tar.gz -C /var/www/html; \

#RUN tar -xzf wordpress-5.7-pt_BR.tar.gz

#RUN wget -r && tar -xzf wordpress.tar.gz -C /var/www/html;

#VOLUME /var/www/html
#WORKDIR /var/www/html

#RUN set -ex; \
#    curl -o wordpress.tar.gz -SL; \
#	tar -xzf wordpress.tar.gz -C /var/www/html
#RUN  tar -xzf wordpress-5.7-pt_BR.tar.gz -C /var/www/html;

#ADD /var/www/html/

RUN curl -LO                         &&\
    tar xvzf latest.tar.gz -C /var/www/html --strip-components=1       &&\
    rm latest.tar.gz                                                   &&\
    chmod -R 755 /var/www/

#RUN curl -o wordpress.tar.gz
#RUN tar -xzvf wordpress.tar.gz --strip-components=1 --directory /var/www/html/
#RUN rm wordpress.tar.gz

file: docker-compose.yml

version: '3.9'

       context: .
       dockerfile: ./Dockerfile
    image: test/wordpress
    container_name: "wordpress"
    restart: "no"
      - wordpress-mysql
      - 80:80
      - "./www/:/var/www/html"

    image: mysql:5.6
    container_name: "wordpress-mysql"
    restart: "no"
      - 3306
      - "./mysql:/var/lib/mysql"

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.

I tried to use the ADD command, including this one in the commented code which I already tried, that line was:

#ADD /var/www/html/
My problem is that it shows downloading and extracting on the console, however when I access the container (by “docker exec -it wordpress bash” ) and give one in the directory (/var/www/html/) it is empty.

Does anyone know what can it be?