DEVCOR Exam QuestionsBrowse all questions from this exam

DEVCOR Exam - Question 151


The access token for a Webex bot has been stored in an environment variable using the command: export bot_token=6bec40cf957de397561557a4fac9ea0

The developer now wants to containerize the Python application which will interact with the bot, and will use this build command to add the token to the build image: docker build --build-arg BOT_TOKEN=$bot_token

Which Dockerfile should be used to build the Docker image so that the bot access token is available as an environment variable?

A.

B.

C.

D.

Show Answer
Correct Answer:

To containerize the Python application and ensure the bot access token is available as an environment variable, you should use a Dockerfile that properly sets the environment variable using the ARG instruction. This allows you to pass the build argument during the build process and then set it as an environment variable inside the Docker container. The most appropriate Dockerfile would be similar to B, but with a correct usage of ARG and ENV. Here's how it should look like to consume the BOT_TOKEN as specified in the build command docker build --build-arg BOT_TOKEN=$bot_token: FROM python:3 RUN apt-get update -y RUN apt-get install -y python-pip python-dev git COPY . /app WORKDIR /app RUN pip3 install -r requirements.txt ARG BOT_TOKEN ENV WEBEX_TEAMS_ACCESS_TOKEN="$BOT_TOKEN" CMD ["python", "bot_app.py"]

Discussion

8 comments
Sign in to comment
ferock
Nov 3, 2022

B Here’s How: While you can’t directly set ENV variable values when running docker build, you can use ARG to pass through --build-arg values right into your ENV instructions. Source: https://vsupalov.com/docker-build-time-env-values/#:~:text=While%20you%20can't%20directly,right%20into%20your%20ENV%20instructions.&text=You%20can%20change%20the%20value,build%20without%20editing%20the%20Dockerfile.

__al__
Oct 2, 2022

B looks like the correct approach

guych77
Nov 24, 2023

D. As the build statement references BOT_TOKEN and not TOKEN so the provided answer is correct in my opinion

ballastleaf8
Dec 22, 2023

I think A and C can be disregarded to the use of the EXPORT statement. Otherwise, both B and D would match the question. Analysing the difference between B and D, ChatGPT has the following view which makes me thing B would be better: To summarize, the key difference is that the first Dockerfile (b) allows for flexibility in passing the value of TOKEN as an argument during the build process, while the second Dockerfile (d) sets the environment variable directly without the ability to override it during the build process.

Zizu007
Apr 5, 2024

B is correct: you can have environment variables (ENV) and build arguments (ARG) with different names in a Dockerfile. In fact, it's common practice to use different names to make their purposes clear and to avoid any potential conflicts or confusion

xorajav691
Aug 4, 2024

None of the answers is correct. The Build Arg is called BOT_TOKEN, and its not consumed in any of the answers. It would need to be: ARG BOT_TOKEN ENV WEBEX...="$BOT_TOKEN"

after_eight
Jan 31, 2024

This should be B. D seems valid enough, but when trying to build the container using the given Dockerfile, i got the following error : [Warning] One or more build-args [BOT_TOKEN] were not consumed thus you have to use ARG command to retrieve ARGs However B is incorrect too, since the ARG syntax is : ARG <my arg>=default My guess is that the correct Dockerfile is ARG BOT_TOKEN ENV WEBEX..="$BOT_TOKEN"

al_mon
Feb 5, 2025

ARG TOKEN=$BOT_TOKEN ENV WEBEX_TEAMS_ACCESS_TOKEN="$TOKEN" CMD ["python", "bot_app.py"] Explanation: ARG TOKEN=$BOT_TOKEN: This allows the build-time argument BOT_TOKEN to be passed using the docker build --build-arg BOT_TOKEN=$bot_token command. The value of BOT_TOKEN (e.g., the Webex bot token) will be available during the build process. ENV WEBEX_TEAMS_ACCESS_TOKEN="$TOKEN": This sets an environment variable WEBEX_TEAMS_ACCESS_TOKEN in the Docker container, making the token available to the application runtime. CMD ["python", "bot_app.py"]: This specifies the command to run the Python application when the container starts.