3

I have got below Dockerfile.

FROM node:boron

# Create app directory
RUN mkdir -p /usr/src/akamai
WORKDIR /usr/src/akamai

# Install app dependencies
COPY package.json /usr/src/akamai/
RUN npm install

# Bundle app source
COPY . /usr/src/akamai

#EXPOSE 8080
CMD ["node", "src/akamai-client.js", "purge", "https://www.example.com/main.css"]

Below is the command which I run from CMD after the docker image build

docker run -it "akamaiapi" //It executes the CMD command as given in above Dockerfile.

CMD ["node", "src/akamai-client.js", "purge", "https://www.example.com/main.css"] //I want these two arguments directly passed from docker command instead hard-coded in Dockerfile, so my Docker run commands could be like these:

docker run -it "akamaiapi" queue
docker run -it "akamaiapi" purge "https://www.example.com/main.css"
docker run -it "akamaiapi" purge-status "b9f80d960602b9f80d960602b9f80d960602"

1 Answer 1

4

You can do that through a combination of ENTRYPOINT and CMD.

  • The ENTRYPOINT specifies a command that will always be executed when the container starts.

  • The CMD specifies arguments that will be fed to the ENTRYPOINT.

So, with Dockerfile:

FROM node:boron
...

ENTRYPOINT ["node", "src/akamai-client.js"]

CMD ["purge", "https://www.example.com/main.css"]

The default behavior of a running container:

docker run -it akamaiapi

would be like command :

node src/akamai-client.js purge "https://www.example.com/main.css"

And if you do :

docker run -it akamaiapi queue

The underlying execution in the container would be like:

node src/akamai-client.js queue
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.