Referencing the first argument passed to the docke

2019-06-03 07:03发布

问题:

I'm trying to obtain the value of the first argument I pass to the Docker Entrypoint. I received an answer earlier on how to do this. Here is the link:

Referencing a dynamic argument in the Docker Entrypoint

So I setup an experiment to see if this works:

Here's my Dockerfile:

FROM alpine:3.3
MAINTAINER ole.ersoy@gmail.com

RUN apk add --update --no-cache --no-progress bash
COPY run.sh .
ENTRYPOINT /run.sh

And the run.sh entrypoint:

#!/bin/sh
echo The first argument is: $1

I then build this:

docker build -t test .

And run the image:

ole@MKI:~/docker-test$ docker run test one
The first argument is:

I was expecting:

ole@MKI:~/docker-test$ docker run test one
The first argument is: one

Thoughts?

TIA, Ole

回答1:

Change ENTRYPOINT to next:

ENTRYPOINT ["bash", "run.sh"]

It works for me. Read more about entrypoint args here https://docs.docker.com/engine/reference/builder/#entrypoint