Docker Community Forums

Share and learn in the Docker community.

Unable to run command when building a image from Dockerfile

Please look below github link - README.MD file where I have explained entire issue.

Any assistance on this issue will really help me.

Github: https://github.com/guptapranay/artillery-tests

Kindly post your thoughts here or in Issue section of github

When you provide an ENTRYPOINT and a CMD in an image, the command line for starting a container is the concatenation of the two, in the order ENTRYPOINT CMD. Going by your Dockerfile, the default command line is artillery --help.

In the docker run command, whatever you type after the image name replaces the CMD, not the ENTRYPOINT. So for example, if you execute docker run aio abc def, the command line will be artillery abc def.

After reading your README file, I think the easiest way to solve your problem would be to change the CMD line in your Dockerfile as follows:

 CMD [ "run","./services/employeeServices/scenarios/create-employee-details.yml","--config","./services/employeeServices/config.yml","--overrides","\"$(cat ./services/employeeServices/overrides.slos.json)\"","-e", "local"]

Note how each element of the CMD is in double quotes, and the actual double quotes have been escaped with a \. That is important.

Hi Raj,

Glad it worked. But I am stuck with a different issues. I am getting a very different output. To explain this:

If you could clone my project and build an image with Dockerfile along with your changes and run container like below - My test just runs with no scenarios.

docker container run aio

But, If I start the container with below command it works fine. If you could build an image and run, you will be able to see how output of the container is different.

docker container run aio run ./services/employeeServices/scenarios/create-employee-details.yml --config ./services/employeeServices/config.yml --overrides "$(cat ./services/employeeServices/overrides.slos.json)" -e local

Any inputs from you will really help me. I believe its not taking files correctly.

My Dockerfile:

FROM node:10.17.0-alpine

LABEL maintainer="Pranay Gupta"

WORKDIR /artillery

RUN chmod 777 /artillery

COPY . .

RUN apk update && apk upgrade && apk add bash
RUN chmod +x ./entrypoint.sh
RUN npm install -g artillery artillery-plugin-expect --unsafe-perm=true --alow-root
RUN npm i --unsafe-perm=true --alow-root

ENTRYPOINT ["artillery"]

CMD [ "run","./services/employeeServices/scenarios/create-employee-details.yml","--config","./services/employeeServices/config.yml","--overrides","\"$(cat ./services/employeeServices/overrides.slos.json)\"","-e", "local"]

On second thought, your entrypoint.sh seemed like a better idea. So I cloned your repo, changed the Dockerfile, built the image and ran the container. It seems to work.

Here’s the Dockerfile:

FROM node:10.17.0-alpine

LABEL maintainer="Pranay Gupta"

WORKDIR /artillery

RUN chmod 777 /artillery

COPY . .

RUN apk update && apk upgrade && apk add bash
RUN chmod +x ./entrypoint.sh
RUN npm install -g artillery artillery-plugin-expect --unsafe-perm=true --alow-root
RUN npm i --unsafe-perm=true --alow-root

ENTRYPOINT ["./entrypoint.sh"]
1 Like

Hi @rajchaudhuri, Thank you so much for this help. It all worked up.

@rajchaudhuri

I apologize for troubling you again. I would like your insight again. I opened another issuer earlier regarding calling declared value in entrypoint.sh file where you clarified my doubt.

Link: https://forums.docker.com/t/how-to-call-value-declared-in-docker-compose-file-in-entrypoint-sh-file/84017/3

The issue is for the same artillery test for which you helped me answer the current answer in this post. I have updated my github project. With your above help, standalone artillery image is working.

Could you guide me to make it work with docker-compose.yml file? The args are not passing in entrypoint.sh file.

Link: https://github.com/guptapranay/artillery-tests