Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile does not allow use of environment variables #8272

Closed
agalazis opened this issue Oct 26, 2023 · 4 comments
Closed

Dockerfile does not allow use of environment variables #8272

agalazis opened this issue Oct 26, 2023 · 4 comments
Assignees
Labels
docker Issue involves the AWS CLI Docker container image response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@agalazis
Copy link

Describe the bug

You cannot state environment variables in aws commands

Expected Behavior

I should be able to use ["s3" , "cp", "${SOURCE}", "${DESTINATION}" ] for exampled where SOURCE and DESTINATION are environment variables

Current Behavior

"${SOURCE}" and "${DESTINATION}" are taken literally as the strings "${SOURCE}" and "${DESTINATION}"

Reproduction Steps

Make an image that USES environment variables in CMD

Possible Solution

After reading about a ancient docker issue., I was able to get environment variables to work by overwriting the entrypoint to a file that contains the following 2 lines:

#!/bin/bash
bash -c "aws $*"

Additional Information/Context

Related docker issue
moby/moby#5509

CLI version used

2

Environment details (OS name and version, etc.)

Linux

@agalazis agalazis added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 26, 2023
@tim-finnigan tim-finnigan self-assigned this Nov 1, 2023
@tim-finnigan
Copy link
Contributor

Hi @agalazis thanks for reaching out. I think this is just a limitation of Docker — here is an explanation.

If you want to pass environment variables you can use the -e flag, for example:

docker run -e SOURCE_BUCKET -e DEST_BUCKET amazon/aws-cli s3 cp s3://$SOURCE_BUCKET/test.txt s3://$DEST_BUCKET/test.txt

Here are more examples in the AWS CLI documentation: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-docker.html#cliv2-docker-share-files

You can also use sh as the ENTRYPOINT:

FROM amazon/aws-cli:latest
ENV TARGET_BUCKET='bucket-name'
ENTRYPOINT [ "sh", "-c", "aws s3 ls s3://$TARGET_BUCKET" ]

@tim-finnigan tim-finnigan added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. docker Issue involves the AWS CLI Docker container image and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 1, 2023
@agalazis
Copy link
Author

agalazis commented Nov 3, 2023

yes that's what I proposed as the default entry point but then when I thought of it it might be a breaking change since people might rely on existing escaping so you can close this ticket. I guess the best option is to extend the base image.
In my case I run fargate tasks and overwriting entrypoint in containerOverrides is not an option... otherwise I wouldn't even need to maintain our own image just for the entrypoint change.

@agalazis
Copy link
Author

agalazis commented Nov 3, 2023

This might cause a breaking change so closing...

@agalazis agalazis closed this as completed Nov 3, 2023
Copy link

github-actions bot commented Nov 3, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker Issue involves the AWS CLI Docker container image response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants