Docker passing variable to shell script executing git clone

I am creating a Docker file and as part of this file, I want to give the end user the ability to pass git in their repository.

I looked at this SO post and several other sites, but got stuck in the syntax git clone.

The clone git command returns an error because the variable that is part of it does not contain a value in the step docker build.

I have this bash script called gitclone.sh

#!/bin/bash
git clone $1 /app

and in my Docker file I have this line:

RUN ./gitclone.sh $LOCATION

The shell of the script has permissions to run, and it works when launched from inside the container, as I pass it the real repository.

During the Docker build phase, I get the following error:

fatal: repository '/ app' does not exist

, $1 , .

Docker ? :

docker run -e LOCATION=https://github.com/something.git -d jwknz/pg02

UPDATE Docker CMD ["../gitclone.sh","$LOCATION"] RUN ./gitclone.sh $LOCATION .

Docker , docker run.

+4
1

-, , Dockerfile ( docker build), docker run .

script. script, , , Dockerfile.

, git apache httpd , script, , , Dockerfile. , . gitCloneAndRunHttpd.sh

#!/bin/bash 

git clone $LOCATION /app 
/usr/local/apache2/bin/apachectl -f /usr/local/apache2/conf/httpd.conf 

Dockerfile , script , , en :

[...]

COPY ["gitCloneAndRunHttpd.sh", "/gitCloneAndRunHttpd.sh"]
RUN chmod +x /gitCloneAndRunHttpd.sh
ENTRYPOINT ["/gitCloneAndRunHttpd.sh"]

docker build, .

, docker run -e LOCATION=https://github.com/some-git-repo.url -d your/image, repo https://github.com/some-git-repo.url /app apache httpd.

. , fooobar.com/questions/203151/..., , (/bin/sh) /file.sh abc - , , file.sh script.

+1

Source: https://habr.com/ru/post/1678491/


All Articles