DockerFile
FROM thoom/pyresttest
ARG url
ENV api_url=$url
COPY ./tests usr/src/app
WORKDIR usr/src/app
ENTRYPOINT [ "pyresttest" ]
RUN echo "Oh dang look at that $url"
CMD [ "$api_url","api_test.yml" ]
api_test.yml
- config:
- testset: "Basic tests"
- timeout: 100 # Increase timeout from the default 10 seconds
- test:
- name: "get"
- url: "/prod/URLS"
- method: "GET"
- expected_status: [200]
- test:
- name: "post"
- url: "/prod/URLS"
- method: "POST"
- body: '{ "url_name": "www.youtube.com" }'
- headers: { "Content-Type": "application/json" }
- expected_status: [200]
- extract_binds:
- "id": { "jsonpath_mini": "Item.url_id" }
- test:
- name: "post"
- url: "/prod/URLS"
- method: "PATCH"
- body: { template: '{"url_name": "www.cnn.com","url_id": "$id"}' }
- headers: { "Content-Type": "application/json" }
- expected_status: [200]
- test:
- name: "post"
- url: "/prod/URLS"
- method: "DELETE"
- body: { template: '{"url_id": "$id"}' }
- headers: { "Content-Type": "application/json" }
- expected_status: [200]
docker build -t rest-api-test . --build-arg
url=myapiurl.com
Im trying to pass my url as build argument to my Dockerfile when I build it but for some reason its not accepting it in CMD and when I run my build file all my tests fail due to url. But when I hardcode my url in CMD all my tests work then. Why CMD is not accepting my url which I'm passing in my --build-args ?
PS: Trying to learn docker because I'm new
CodePudding user response:
You're using the exec form of the CMD statement. That doesn't run a shell, so you can't use environment variables in your command.
You can run a shell in your CMD statement in 2 ways. Either use the shell form
CMD $api_url api_test.yml
or the exec form where you run the shell explicitly
CMD ["/bin/sh", "-c", "$api_url apt_test.yml"]