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"
Manoj Singh
  • 7,569
  • 34
  • 119
  • 198

1 Answers1

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
François Maturel
  • 5,884
  • 6
  • 45
  • 50