Skip to content

Commit 4dc961d

Browse files
committed
image-inspect: remove Config fields that are not part of the image
commit af0cdc3 marked these fields as deprecated and to be removed in API v1.47 (which was targeted for v28.0). We shipped v1.47 with the v27.2 release, but did not yet remove the erroneous fields, so the version to deprecate was updated to v1.48 through 3df03d8 This patch removes fields that are not part of the image by replacing the type with the Config struct from the docker image-spec. curl -s --unix-socket /var/run/docker.sock http://localhost/v1.50/images/alpine/json | jq .Config { "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "/bin/sh" ] } curl -s --unix-socket /var/run/docker.sock http://localhost/v1.49/images/alpine/json | jq .Config { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "/bin/sh" ], "Image": "", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": null } Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent b1c0bfa commit 4dc961d

10 files changed

Lines changed: 100 additions & 154 deletions

File tree

api/server/router/image/image_routes.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/docker/docker/api"
1616
"github.com/docker/docker/api/server/httputils"
1717
"github.com/docker/docker/api/types/backend"
18+
"github.com/docker/docker/api/types/container"
1819
"github.com/docker/docker/api/types/filters"
1920
imagetypes "github.com/docker/docker/api/types/image"
2021
"github.com/docker/docker/api/types/registry"
@@ -26,6 +27,8 @@ import (
2627
"github.com/docker/docker/pkg/ioutils"
2728
"github.com/docker/docker/pkg/progress"
2829
"github.com/docker/docker/pkg/streamformatter"
30+
"github.com/docker/go-connections/nat"
31+
dockerspec "github.com/moby/docker-image-spec/specs-go/v1"
2932
"github.com/opencontainers/go-digest"
3033
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3134
"github.com/pkg/errors"
@@ -388,6 +391,17 @@ func (ir *imageRouter) getImagesByName(ctx context.Context, w http.ResponseWrite
388391
if versions.LessThan(version, "1.48") {
389392
imageInspect.Descriptor = nil
390393
}
394+
if versions.LessThan(version, "1.50") {
395+
type imageInspectLegacy struct {
396+
imagetypes.InspectResponse
397+
LegacyConfig *container.Config `json:"Config"`
398+
}
399+
return httputils.WriteJSON(w, http.StatusOK, imageInspectLegacy{
400+
InspectResponse: *imageInspect,
401+
LegacyConfig: dockerOCIImageConfigToContainerConfig(*imageInspect.Config),
402+
})
403+
}
404+
391405
return httputils.WriteJSON(w, http.StatusOK, imageInspect)
392406
}
393407

@@ -571,3 +585,27 @@ func validateRepoName(name reference.Named) error {
571585
}
572586
return nil
573587
}
588+
589+
// FIXME(thaJeztah): this is a copy of dockerOCIImageConfigToContainerConfig in daemon/containerd: https://github.com/moby/moby/blob/6b617699c500522aa6526cfcae4558333911b11f/daemon/containerd/imagespec.go#L107-L128
590+
func dockerOCIImageConfigToContainerConfig(cfg dockerspec.DockerOCIImageConfig) *container.Config {
591+
exposedPorts := make(nat.PortSet, len(cfg.ExposedPorts))
592+
for k, v := range cfg.ExposedPorts {
593+
exposedPorts[nat.Port(k)] = v
594+
}
595+
596+
return &container.Config{
597+
Entrypoint: cfg.Entrypoint,
598+
Env: cfg.Env,
599+
Cmd: cfg.Cmd,
600+
User: cfg.User,
601+
WorkingDir: cfg.WorkingDir,
602+
ExposedPorts: exposedPorts,
603+
Volumes: cfg.Volumes,
604+
Labels: cfg.Labels,
605+
ArgsEscaped: cfg.ArgsEscaped, //nolint:staticcheck // Ignore SA1019. Need to keep it in image.
606+
StopSignal: cfg.StopSignal,
607+
Healthcheck: cfg.Healthcheck,
608+
OnBuild: cfg.OnBuild,
609+
Shell: cfg.Shell,
610+
}
611+
}

api/swagger.yaml

Lines changed: 0 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,63 +1428,10 @@ definitions:
14281428
when starting a container from the image.
14291429
type: "object"
14301430
properties:
1431-
Hostname:
1432-
description: |
1433-
The hostname to use for the container, as a valid RFC 1123 hostname.
1434-
1435-
<p><br /></p>
1436-
1437-
> **Deprecated**: this field is not part of the image specification and is
1438-
> always empty. It must not be used, and will be removed in API v1.48.
1439-
type: "string"
1440-
example: ""
1441-
Domainname:
1442-
description: |
1443-
The domain name to use for the container.
1444-
1445-
<p><br /></p>
1446-
1447-
> **Deprecated**: this field is not part of the image specification and is
1448-
> always empty. It must not be used, and will be removed in API v1.48.
1449-
type: "string"
1450-
example: ""
14511431
User:
14521432
description: "The user that commands are run as inside the container."
14531433
type: "string"
14541434
example: "web:web"
1455-
AttachStdin:
1456-
description: |
1457-
Whether to attach to `stdin`.
1458-
1459-
<p><br /></p>
1460-
1461-
> **Deprecated**: this field is not part of the image specification and is
1462-
> always false. It must not be used, and will be removed in API v1.48.
1463-
type: "boolean"
1464-
default: false
1465-
example: false
1466-
AttachStdout:
1467-
description: |
1468-
Whether to attach to `stdout`.
1469-
1470-
<p><br /></p>
1471-
1472-
> **Deprecated**: this field is not part of the image specification and is
1473-
> always false. It must not be used, and will be removed in API v1.48.
1474-
type: "boolean"
1475-
default: false
1476-
example: false
1477-
AttachStderr:
1478-
description: |
1479-
Whether to attach to `stderr`.
1480-
1481-
<p><br /></p>
1482-
1483-
> **Deprecated**: this field is not part of the image specification and is
1484-
> always false. It must not be used, and will be removed in API v1.48.
1485-
type: "boolean"
1486-
default: false
1487-
example: false
14881435
ExposedPorts:
14891436
description: |
14901437
An object mapping ports to an empty object in the form:
@@ -1501,39 +1448,6 @@ definitions:
15011448
"80/tcp": {},
15021449
"443/tcp": {}
15031450
}
1504-
Tty:
1505-
description: |
1506-
Attach standard streams to a TTY, including `stdin` if it is not closed.
1507-
1508-
<p><br /></p>
1509-
1510-
> **Deprecated**: this field is not part of the image specification and is
1511-
> always false. It must not be used, and will be removed in API v1.48.
1512-
type: "boolean"
1513-
default: false
1514-
example: false
1515-
OpenStdin:
1516-
description: |
1517-
Open `stdin`
1518-
1519-
<p><br /></p>
1520-
1521-
> **Deprecated**: this field is not part of the image specification and is
1522-
> always false. It must not be used, and will be removed in API v1.48.
1523-
type: "boolean"
1524-
default: false
1525-
example: false
1526-
StdinOnce:
1527-
description: |
1528-
Close `stdin` after one attached client disconnects.
1529-
1530-
<p><br /></p>
1531-
1532-
> **Deprecated**: this field is not part of the image specification and is
1533-
> always false. It must not be used, and will be removed in API v1.48.
1534-
type: "boolean"
1535-
default: false
1536-
example: false
15371451
Env:
15381452
description: |
15391453
A list of environment variables to set inside the container in the
@@ -1559,18 +1473,6 @@ definitions:
15591473
default: false
15601474
example: false
15611475
x-nullable: true
1562-
Image:
1563-
description: |
1564-
The name (or reference) of the image to use when creating the container,
1565-
or which was used when the container was created.
1566-
1567-
<p><br /></p>
1568-
1569-
> **Deprecated**: this field is not part of the image specification and is
1570-
> always empty. It must not be used, and will be removed in API v1.48.
1571-
type: "string"
1572-
default: ""
1573-
example: ""
15741476
Volumes:
15751477
description: |
15761478
An object mapping mount point paths inside the container to empty
@@ -1599,30 +1501,6 @@ definitions:
15991501
items:
16001502
type: "string"
16011503
example: []
1602-
NetworkDisabled:
1603-
description: |
1604-
Disable networking for the container.
1605-
1606-
<p><br /></p>
1607-
1608-
> **Deprecated**: this field is not part of the image specification and is
1609-
> always omitted. It must not be used, and will be removed in API v1.48.
1610-
type: "boolean"
1611-
default: false
1612-
example: false
1613-
x-nullable: true
1614-
MacAddress:
1615-
description: |
1616-
MAC address of the container.
1617-
1618-
<p><br /></p>
1619-
1620-
> **Deprecated**: this field is not part of the image specification and is
1621-
> always omitted. It must not be used, and will be removed in API v1.48.
1622-
type: "string"
1623-
default: ""
1624-
example: ""
1625-
x-nullable: true
16261504
OnBuild:
16271505
description: |
16281506
`ONBUILD` metadata that were defined in the image's `Dockerfile`.
@@ -1645,17 +1523,6 @@ definitions:
16451523
type: "string"
16461524
example: "SIGTERM"
16471525
x-nullable: true
1648-
StopTimeout:
1649-
description: |
1650-
Timeout to stop a container in seconds.
1651-
1652-
<p><br /></p>
1653-
1654-
> **Deprecated**: this field is not part of the image specification and is
1655-
> always omitted. It must not be used, and will be removed in API v1.48.
1656-
type: "integer"
1657-
default: 10
1658-
x-nullable: true
16591526
Shell:
16601527
description: |
16611528
Shell for when `RUN`, `CMD`, and `ENTRYPOINT` uses a shell.
@@ -1666,19 +1533,11 @@ definitions:
16661533
example: ["/bin/sh", "-c"]
16671534
# FIXME(thaJeztah): temporarily using a full example to remove some "omitempty" fields. Remove once the fields are removed.
16681535
example:
1669-
"Hostname": ""
1670-
"Domainname": ""
16711536
"User": "web:web"
1672-
"AttachStdin": false
1673-
"AttachStdout": false
1674-
"AttachStderr": false
16751537
"ExposedPorts": {
16761538
"80/tcp": {},
16771539
"443/tcp": {}
16781540
}
1679-
"Tty": false
1680-
"OpenStdin": false
1681-
"StdinOnce": false
16821541
"Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"]
16831542
"Cmd": ["/bin/sh"]
16841543
"Healthcheck": {
@@ -1690,7 +1549,6 @@ definitions:
16901549
"StartInterval": 0
16911550
}
16921551
"ArgsEscaped": true
1693-
"Image": ""
16941552
"Volumes": {
16951553
"/app/data": {},
16961554
"/app/config": {}

api/types/backend/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ type ImageInspectOpts struct {
160160
type CommitConfig struct {
161161
Author string
162162
Comment string
163-
Config *container.Config
163+
Config *container.Config // TODO(thaJeztah); change this to [dockerspec.DockerOCIImageConfig]
164164
ContainerConfig *container.Config
165165
ContainerID string
166166
ContainerMountLabel string

api/types/image/image_inspect.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package image
33
import (
44
"github.com/docker/docker/api/types/container"
55
"github.com/docker/docker/api/types/storage"
6+
dockerspec "github.com/moby/docker-image-spec/specs-go/v1"
67
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
78
)
89

@@ -84,7 +85,7 @@ type InspectResponse struct {
8485
// Author is the name of the author that was specified when committing the
8586
// image, or as specified through MAINTAINER (deprecated) in the Dockerfile.
8687
Author string
87-
Config *container.Config
88+
Config *dockerspec.DockerOCIImageConfig
8889

8990
// Architecture is the hardware CPU architecture that the image runs on.
9091
Architecture string

daemon/containerd/image_inspect.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ func (i *ImageService) ImageInspect(ctx context.Context, refOrID string, opts ba
108108
}
109109

110110
if multi.Best != nil {
111+
imgConfig := img.Config
111112
resp.Author = img.Author
112-
resp.Config = dockerOCIImageConfigToContainerConfig(img.Config)
113+
resp.Config = &imgConfig
113114
resp.Architecture = img.Architecture
114115
resp.Variant = img.Variant
115116
resp.Os = img.OS

daemon/images/image_inspect.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (i *ImageService) ImageInspect(ctx context.Context, refOrID string, opts ba
5353
layers = append(layers, l.String())
5454
}
5555

56+
imgConfig := containerConfigToDockerOCIImageConfig(img.Config)
5657
return &imagetypes.InspectResponse{
5758
ID: img.ID().String(),
5859
RepoTags: repoTags,
@@ -64,7 +65,7 @@ func (i *ImageService) ImageInspect(ctx context.Context, refOrID string, opts ba
6465
ContainerConfig: &img.ContainerConfig, //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.45.
6566
DockerVersion: img.DockerVersion,
6667
Author: img.Author,
67-
Config: img.Config,
68+
Config: &imgConfig,
6869
Architecture: img.Architecture,
6970
Variant: img.Variant,
7071
Os: img.OperatingSystem(),

daemon/images/imagespec.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package images
2+
3+
import (
4+
"github.com/docker/docker/api/types/container"
5+
imagespec "github.com/moby/docker-image-spec/specs-go/v1"
6+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
7+
)
8+
9+
func containerConfigToDockerOCIImageConfig(cfg *container.Config) imagespec.DockerOCIImageConfig {
10+
var ociCfg ocispec.ImageConfig
11+
var ext imagespec.DockerOCIImageConfigExt
12+
13+
if cfg != nil {
14+
ociCfg = ocispec.ImageConfig{
15+
User: cfg.User,
16+
Env: cfg.Env,
17+
Entrypoint: cfg.Entrypoint,
18+
Cmd: cfg.Cmd,
19+
Volumes: cfg.Volumes,
20+
WorkingDir: cfg.WorkingDir,
21+
Labels: cfg.Labels,
22+
StopSignal: cfg.StopSignal,
23+
ArgsEscaped: cfg.ArgsEscaped, //nolint:staticcheck // Ignore SA1019. Need to keep it in image.
24+
}
25+
26+
if len(cfg.ExposedPorts) > 0 {
27+
ociCfg.ExposedPorts = map[string]struct{}{}
28+
for k, v := range cfg.ExposedPorts {
29+
ociCfg.ExposedPorts[string(k)] = v
30+
}
31+
}
32+
ext.Healthcheck = cfg.Healthcheck
33+
ext.OnBuild = cfg.OnBuild
34+
ext.Shell = cfg.Shell
35+
}
36+
37+
return imagespec.DockerOCIImageConfig{
38+
ImageConfig: ociCfg,
39+
DockerOCIImageConfigExt: ext,
40+
}
41+
}

docs/api/version-history.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ keywords: "API, Docker, rcli, REST, documentation"
2424
* Deprecated: The `BridgeNfIptables` and `BridgeNfIp6tables` fields in the
2525
`GET /info` response were deprecated in API v1.48, and are now omitted
2626
in API v1.50.
27+
* Deprecated: `GET /images/{name}/json` no longer returns the following `Config`
28+
fields; `Hostname`, `Domainname`, `AttachStdin`, `AttachStdout`, `AttachStderr`
29+
`Tty`, `OpenStdin`, `StdinOnce`, `Image`, `NetworkDisabled` (already omitted unless set),
30+
`MacAddress` (already omitted unless set), `StopTimeout` (already omitted unless set).
31+
These additional fields were included in the response due to an implementation
32+
detail but not part of the image's Configuration. These fields were marked
33+
deprecated in API v1.46, and are now omitted. Older versions of the API still
34+
return these fields, but they are always empty.
2735

2836
## v1.49 API changes
2937

hack/make/test-docker-py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ if [ -n "$TEST_INTEGRATION_USE_SNAPSHOTTER" ]; then
2222
PY_TEST_OPTIONS="$PY_TEST_OPTIONS --deselect=tests/integration/api_build_test.py::BuildTest::test_build_squash"
2323
fi
2424

25+
# TODO(thaJeztah) re-enable after https://github.com/docker/docker-py/pull/3336 is in the DOCKER_PY_COMMIT release.
26+
PY_TEST_OPTIONS="$PY_TEST_OPTIONS --deselect=tests/integration/api_build_test.py::BuildTest::test_build_container_with_target"
27+
2528
# TODO(vvoland): re-enable after https://github.com/docker/docker-py/pull/3203 is included in the DOCKER_PY_COMMIT release.
2629
PY_TEST_OPTIONS="$PY_TEST_OPTIONS --deselect=tests/integration/api_image_test.py::CommitTest::test_commit"
2730
PY_TEST_OPTIONS="$PY_TEST_OPTIONS --deselect=tests/integration/api_image_test.py::CommitTest::test_commit_with_changes"

0 commit comments

Comments
 (0)