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

add env and user to inspect in dockercompat #4007

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Shubhranshu153
Copy link
Contributor

@Shubhranshu153 Shubhranshu153 commented Mar 14, 2025

Issue:
Docker Compat Inspect doesn't have Env and User parameter for the process

Description:
This PR adds Env and User for the docker compat inspect

Test:

  1. Before adding the Env
   "Config": {
            "Hostname": "8ef7e6dbae24",
            "AttachStdin": false,
            "Labels": {
                "dev.containers.id": "base-alpine",
                "dev.containers.release": "v0.4.10",
}
  1. After adding the Env:
    "Config": {
      "Hostname": "08826b4795c7",
      "AttachStdin": false,
      "Env": [
        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
        "HOSTNAME=08826b4795c7"
      ],
  "Labels": {
        "dev.containers.id": "base-alpine",
        "dev.containers.release": "v0.4.10",

}

  1. Before adding the User
   "Config": {
            "Hostname": "8ef7e6dbae24",
            "AttachStdin": false,
            "Labels": {
                "dev.containers.id": "base-alpine",
                "dev.containers.release": "v0.4.10",
}
  1. After adding the User
 "Config": {
            "Hostname": "5dceef466aa1",
            "User": "test",
            "AttachStdin": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "HOSTNAME=5dceef466aa1"
            ],
            "Labels": {
                "devcontainer.config_file": "/Users/shubhum/Documents/devcontainers/.devcontainer/devcontainer.json",
                "devcontainer.local_folder": "/Users/shubhum/Documents/devcontainers",
                }

Signed-off-by: Shubharanshu Mahapatra <[email protected]>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda added this to the v2.0.4 milestone Mar 14, 2025
@@ -540,6 +540,12 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
pidMode = n.Labels[labels.PIDContainer]
}
c.HostConfig.PidMode = pidMode

Copy link
Contributor

Choose a reason for hiding this comment

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

Should c.Config.Env be initialized as an empty list or should the else condition leave the Env key-value pair, in the case that the conditional criteria fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

empty list as not having the key can lead to errors downstream if they query for env from the unmarshalled json and they dont handle key not being present. And also would represent if container process has no set env variables.

Signed-off-by: Shubharanshu Mahapatra <[email protected]>
@Shubhranshu153 Shubhranshu153 changed the title add env to inspect add env and user to inspect in dockercompat Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants