Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile custom commands/directives

I've been reading through the Docker documentation and can't seem to work out if its possible to create a custom command/directive. Basically I need to make an HTTP request to external service to retrieve some assets that need to be included within my container. Rather than referencing them using Volumes I want to effectively inject them into the container during the build process, a bit like dependancy injection.

like image 969
user1513388 Avatar asked Oct 15 '25 01:10

user1513388


1 Answers

Assuming you are referring to download some files using http (HTTP GET) as one of the example in the question. You can try this.

RUN wget https://wordpress.org/plugins/about/readme.txt

or

RUN curl https://wordpress.org/plugins/about/readme.txt

The example Dockerfile with download shell script

PROJ-DIR
    - files
        - test.sh
    - Dockerfile

files/test.sh

#!/bin/sh

wget https://wordpress.org/plugins/about/readme.txt

Dockerfile

FROM centos:latest

COPY files/test.sh /opt/
RUN chmod u+x /opt/test.sh

RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
RUN yes | yum install wget

RUN /opt/test.sh
RUN rm /opt/test.sh

Build the image

docker build -t test_img .
like image 58
spectre007 Avatar answered Oct 17 '25 15:10

spectre007



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!