Skip to content

Update config/secret handling: Copy files into containers instead of bind mounting - #11984

Closed
schaubl wants to merge 1 commit into
docker:mainfrom
SixSq:fix-configs-secrets
Closed

schaubl wants to merge 1 commit into
docker:mainfrom
SixSq:fix-configs-secrets

Conversation

@schaubl

@schaubl schaubl commented Jul 16, 2024

Copy link
Copy Markdown

Currently, Docker Compose copies a config or secret into the container if the source is an environment variable or inlined content. However, if the source is a file, the file is bind mounted into the container. This approach fails when Docker Compose is invoked on a different filesystem than the Docker daemon host filesystem (e.g., when called from within a container or remotely using the -H option).

This PR changes the behavior for file-based config/secret sources to match the handling of environment variables and inlined content. Specifically, it reads the file from the filesystem where Docker Compose is executed (like Docker Stack) and copies it into the container.

This update enhances the functionality of Docker Compose when run "remotely," providing the ability to push configuration files, a feature previously available only with Docker Stack/Swarm.

What I did:

  • Updated the behavior for handling configs and secrets sourced from files.
  • Ensured consistency with the documentation and the behavior of Docker Stack.
  • Enabled Docker Compose to push configuration files when run remotely, aligning with Docker Stack/Swarm capabilities.

@schaubl

schaubl commented Jul 17, 2024

Copy link
Copy Markdown
Author

I realized that this PR is a duplicate of #11871.

I think the PR #11871 could benefit from the changes in the file pkg/compose/create.go made in this PR.
It basically keeps some checks and adds a preflight check to ensure the file used as the source for config/secret can be accessed so that if it's not the case it will fail before creating the container.

I will also add this suggestion in a comment on #11871.

…it into the container

Signed-off-by: schaubl <schaubl@users.noreply.github.com>
@schaubl
schaubl force-pushed the fix-configs-secrets branch from c08e5c8 to f54922f Compare July 20, 2024 16:23

@ndeloof ndeloof left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One challenge we need to address here is that we have some users who rely on bind mounts being used. While a simple workaround is for them to declare an explicit bind mount, this would still be a breaking change.

Comment thread pkg/compose/secrets.go
}
content = env
} else if file.File != "" {
data, err := os.ReadFile(file.File)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file can actually be a folder. Need to change logic here to produce tar, not just extract content

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants