Skip to content

Commit 4283289

Browse files
committed
Deprecate /containers/(id or name)/copy endpoint
This endpoint has been deprecated since 1.8. Return an error starting from this API version (1.24) in order to make sure it's not used for the next API version and so that we can remove it some times later. Signed-off-by: Vincent Demeester <[email protected]>
1 parent 020a86b commit 4283289

6 files changed

Lines changed: 40 additions & 39 deletions

File tree

api/server/router/container/container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (r *containerRouter) initRoutes() {
6262
router.NewPostRoute("/containers/{name:.*}/wait", r.postContainersWait),
6363
router.NewPostRoute("/containers/{name:.*}/resize", r.postContainersResize),
6464
router.NewPostRoute("/containers/{name:.*}/attach", r.postContainersAttach),
65-
router.NewPostRoute("/containers/{name:.*}/copy", r.postContainersCopy),
65+
router.NewPostRoute("/containers/{name:.*}/copy", r.postContainersCopy), // Deprecated since 1.8, Errors out since 1.12
6666
router.NewPostRoute("/containers/{name:.*}/exec", r.postContainerExecCreate),
6767
router.NewPostRoute("/exec/{name:.*}/start", r.postContainerExecStart),
6868
router.NewPostRoute("/exec/{name:.*}/resize", r.postContainerExecResize),

api/server/router/container/copy.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ import (
1111

1212
"github.com/docker/docker/api/server/httputils"
1313
"github.com/docker/engine-api/types"
14+
"github.com/docker/engine-api/types/versions"
1415
"golang.org/x/net/context"
1516
)
1617

1718
// postContainersCopy is deprecated in favor of getContainersArchive.
1819
func (s *containerRouter) postContainersCopy(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
20+
// Deprecated since 1.8, Errors out since 1.12
21+
version := httputils.VersionFromContext(ctx)
22+
if versions.GreaterThanOrEqualTo(version, "1.24") {
23+
w.WriteHeader(http.StatusNotFound)
24+
return nil
25+
}
1926
if err := httputils.CheckForJSON(r); err != nil {
2027
return err
2128
}

docs/deprecated.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ The docker login command is removing the ability to automatically register for a
2828

2929
The flag `--security-opt` doesn't use the colon separator(`:`) anymore to divide keys and values, it uses the equal symbol(`=`) for consinstency with other similar flags, like `--storage-opt`.
3030

31+
### `/containers/(id or name)/copy` endpoint
32+
33+
**Deprecated In Release: v1.8**
34+
35+
**Removed In Release: v1.12.0**
36+
37+
The endpoint `/containers/(id or name)/copy` is deprecated in favor of `/containers/(id or name)/archive`.
38+
3139
### Ambiguous event fields in API
3240
**Deprecated In Release: v1.10**
3341

docs/reference/api/docker_remote_api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ This section lists each version from latest to oldest. Each listing includes a
125125
* `POST /containers/(id or name)/start` no longer accepts a `HostConfig`.
126126
* `POST /images/(name)/tag` no longer has a `force` query parameter.
127127
* `GET /images/search` now supports maximum returned search results `limit`.
128+
* `POST /containers/{name:.*}/copy` is now removed and errors out starting from this API version.
128129

129130
### v1.23 API changes
130131

docs/reference/api/docker_remote_api_v1.24.md

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,36 +1389,6 @@ Status Codes:
13891389
- **404** – no such container
13901390
- **500** – server error
13911391

1392-
### Copy files or folders from a container
1393-
1394-
`POST /containers/(id or name)/copy`
1395-
1396-
Copy files or folders of container `id`
1397-
1398-
**Deprecated** in favor of the `archive` endpoint below.
1399-
1400-
**Example request**:
1401-
1402-
POST /containers/4fa6e0f0c678/copy HTTP/1.1
1403-
Content-Type: application/json
1404-
1405-
{
1406-
"Resource": "test.txt"
1407-
}
1408-
1409-
**Example response**:
1410-
1411-
HTTP/1.1 200 OK
1412-
Content-Type: application/x-tar
1413-
1414-
{{ TAR STREAM }}
1415-
1416-
Status Codes:
1417-
1418-
- **200** – no error
1419-
- **404** – no such container
1420-
- **500** – server error
1421-
14221392
### Retrieving information about files and folders in a container
14231393

14241394
`HEAD /containers/(id or name)/archive`

integration-cli/docker_api_containers_test.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ func (s *DockerSuite) TestContainerApiWait(c *check.C) {
892892
c.Assert(waitres.StatusCode, checker.Equals, 0)
893893
}
894894

895-
func (s *DockerSuite) TestContainerApiCopy(c *check.C) {
895+
func (s *DockerSuite) TestContainerApiCopyNotExistsAnyMore(c *check.C) {
896896
// TODO Windows to Windows CI. This can be ported.
897897
testRequires(c, DaemonIsLinux)
898898
name := "test-container-api-copy"
@@ -902,7 +902,22 @@ func (s *DockerSuite) TestContainerApiCopy(c *check.C) {
902902
Resource: "/test.txt",
903903
}
904904

905-
status, body, err := sockRequest("POST", "/containers/"+name+"/copy", postData)
905+
status, _, err := sockRequest("POST", "/containers/"+name+"/copy", postData)
906+
c.Assert(err, checker.IsNil)
907+
c.Assert(status, checker.Equals, http.StatusNotFound)
908+
}
909+
910+
func (s *DockerSuite) TestContainerApiCopyPre124(c *check.C) {
911+
// TODO Windows to Windows CI. This can be ported.
912+
testRequires(c, DaemonIsLinux)
913+
name := "test-container-api-copy"
914+
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt")
915+
916+
postData := types.CopyConfig{
917+
Resource: "/test.txt",
918+
}
919+
920+
status, body, err := sockRequest("POST", "/v1.23/containers/"+name+"/copy", postData)
906921
c.Assert(err, checker.IsNil)
907922
c.Assert(status, checker.Equals, http.StatusOK)
908923

@@ -923,7 +938,7 @@ func (s *DockerSuite) TestContainerApiCopy(c *check.C) {
923938
c.Assert(found, checker.True)
924939
}
925940

926-
func (s *DockerSuite) TestContainerApiCopyResourcePathEmpty(c *check.C) {
941+
func (s *DockerSuite) TestContainerApiCopyResourcePathEmptyPr124(c *check.C) {
927942
// TODO Windows to Windows CI. This can be ported.
928943
testRequires(c, DaemonIsLinux)
929944
name := "test-container-api-copy-resource-empty"
@@ -933,13 +948,13 @@ func (s *DockerSuite) TestContainerApiCopyResourcePathEmpty(c *check.C) {
933948
Resource: "",
934949
}
935950

936-
status, body, err := sockRequest("POST", "/containers/"+name+"/copy", postData)
951+
status, body, err := sockRequest("POST", "/v1.23/containers/"+name+"/copy", postData)
937952
c.Assert(err, checker.IsNil)
938953
c.Assert(status, checker.Equals, http.StatusInternalServerError)
939954
c.Assert(string(body), checker.Matches, "Path cannot be empty\n")
940955
}
941956

942-
func (s *DockerSuite) TestContainerApiCopyResourcePathNotFound(c *check.C) {
957+
func (s *DockerSuite) TestContainerApiCopyResourcePathNotFoundPre124(c *check.C) {
943958
// TODO Windows to Windows CI. This can be ported.
944959
testRequires(c, DaemonIsLinux)
945960
name := "test-container-api-copy-resource-not-found"
@@ -949,18 +964,18 @@ func (s *DockerSuite) TestContainerApiCopyResourcePathNotFound(c *check.C) {
949964
Resource: "/notexist",
950965
}
951966

952-
status, body, err := sockRequest("POST", "/containers/"+name+"/copy", postData)
967+
status, body, err := sockRequest("POST", "/v1.23/containers/"+name+"/copy", postData)
953968
c.Assert(err, checker.IsNil)
954969
c.Assert(status, checker.Equals, http.StatusInternalServerError)
955970
c.Assert(string(body), checker.Matches, "Could not find the file /notexist in container "+name+"\n")
956971
}
957972

958-
func (s *DockerSuite) TestContainerApiCopyContainerNotFound(c *check.C) {
973+
func (s *DockerSuite) TestContainerApiCopyContainerNotFoundPr124(c *check.C) {
959974
postData := types.CopyConfig{
960975
Resource: "/something",
961976
}
962977

963-
status, _, err := sockRequest("POST", "/containers/notexists/copy", postData)
978+
status, _, err := sockRequest("POST", "/v1.23/containers/notexists/copy", postData)
964979
c.Assert(err, checker.IsNil)
965980
c.Assert(status, checker.Equals, http.StatusNotFound)
966981
}

0 commit comments

Comments
 (0)