Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

dockerfile - docker run pass arguments to entrypoint

I am able to pass the environment variables using -e option. But i am not sure how to pass command line arguments to the jar in entrypoint using the docker run command.

Dockerfile

FROM openjdk
ADD . /dir
WORKDIR /dir
COPY ./test-1.0.1.jar /dir/test-1.0.1.jar
ENTRYPOINT java -jar /dir/test-1.0.1.jar

test.sh

#! /bin/bash -l

export AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id)
export AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key)

$value=7

docker run -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY  -i -t testjava  $value
question from:https://stackoverflow.com/questions/53543881/docker-run-pass-arguments-to-entrypoint

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use ENTRYPOINT in its exec form

ENTRYPOINT ["java", "-jar", "/dir/test-1.0.1.jar"]

then when you run docker run -it testjava $value, $value will be "appended" after your entrypoint, just like java -jar /dir/test-1.0.1.jar $value


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...