user1513388
user1513388

Reputation: 7441

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.

Upvotes: 4

Views: 1497

Answers (1)

spectre007
spectre007

Reputation: 1539

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 .

Upvotes: 4

Related Questions