moby/daemon
Sebastiaan van Stijn e424343b43
Fix conflicting container name producint 400 error instead of 409
Commit ebcb7d6b40 removed string checking
for error messages, in favor of typed errors.

In this change, the status code for conflicting container  names
changed from 409 to 400 (validationError).

This patch add a `nameConflictError`, changing the status code to
409 as it was in older versions.

With this change applied, the correct 409 status is returned:

```bash
$ docker create --name c1 busybox
```

```bash
$ curl --unix-socket /var/run/docker.sock -v -XPOST -H"Content-Type: application/json" -d'{"Image":"busybox"}' http://localhost/containers/create?name=c1
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying /var/run/docker.sock...
* Connected to localhost (/var/run/docker.sock) port 80 (#0)
> POST /containers/create?name=c1 HTTP/1.1
> Host: localhost
> User-Agent: curl/7.52.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 19
>
* upload completely sent off: 19 out of 19 bytes
< HTTP/1.1 409 Conflict
< Api-Version: 1.33
< Content-Type: application/json
< Docker-Experimental: false
< Ostype: linux
< Server: Docker/17.06.0-dev (linux)
< Date: Thu, 28 Sep 2017 15:07:23 GMT
< Content-Length: 229
<
{"message":"Conflict. The container name \"/c1\" is already in use by container \"ed2efdc806c1883954e677eb9ab8cbc7e286c9c5934ef6724fd5d93c56744923\". You have to remove (or rename) that container to be able to reuse that name."}
* Curl_http_done: called premature == 0
* Connection #0 to host localhost left intact
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-10-04 20:39:45 +02:00
..
caps Replace execdrivers with containerd implementation 2016-03-18 13:38:32 -07:00
cluster Merge pull request #34990 from pradipd/update_field_name 2017-09-27 20:00:18 +02:00
config Merge pull request #34821 from thaJeztah/remove-enable-api-cors 2017-09-13 20:10:27 -07:00
discovery Add ineffassign linter 2017-09-08 18:23:21 -04:00
events Merge pull request #34985 from thaJeztah/remove-use-of-deprecated-filter-functions 2017-09-27 17:34:07 +02:00
exec Add gosimple linter 2017-09-12 12:09:59 -04:00
graphdriver Merge pull request #34342 from coolljt0725/fallback_to_naive_diff 2017-10-03 06:45:17 -07:00
initlayer LCOW: Implemented support for docker cp + build 2017-09-14 12:07:52 -07:00
links use t.Fatal() to output the err message where the values used for formatting 2017-02-23 10:16:22 +08:00
listeners Add unconvert linter 2017-08-24 15:08:31 -04:00
logger Move jsonlog to a subpackage of jsonfilelog 2017-09-25 16:07:25 -04:00
names Move names to a more appropriate package. 2017-09-06 12:05:16 -04:00
network Updating moby to correspond to naming convention used in https://github.com/docker/swarmkit/pull/2385 2017-09-26 22:08:10 +00:00
stats Remove string checking in API error handling 2017-08-15 16:01:11 -04:00
testdata Remove libtrust dep from api 2017-09-06 12:05:19 -04:00
apparmor_default.go apparmor: make pkg/aaparser work on read-only root 2017-05-18 00:05:13 +10:00
apparmor_default_unsupported.go daemon: switch to 'ensure' workflow for AppArmor profiles 2016-12-07 08:47:28 +11:00
archive.go LCOW: Implemented support for docker cp + build 2017-09-14 12:07:52 -07:00
archive_tarcopyoptions.go Partial refactor of UID/GID usage to use a unified struct. 2017-06-07 11:44:33 -04:00
archive_tarcopyoptions_unix.go Fix vfs unit test and port VFS to the new IDMappings 2017-06-07 11:44:34 -04:00
archive_tarcopyoptions_windows.go daemon/archive.go: Fix copy routines to preserve UID. 2017-04-12 10:33:19 +00:00
archive_unix.go Volume refactoring for LCOW 2017-09-14 12:33:31 -07:00
archive_windows.go Remove CopyOnBuild from the daemon. 2017-06-08 15:06:54 -04:00
attach.go Optimize some wrong usage and spelling 2017-09-07 09:44:08 +08:00
auth.go Add engine-api types to docker 2016-09-07 11:05:58 -07:00
bindmount_solaris.go Add functional support for Docker sub commands on Solaris 2016-11-07 09:06:34 -08:00
bindmount_unix.go Add functional support for Docker sub commands on Solaris 2016-11-07 09:06:34 -08:00
build.go LCOW: Implemented support for docker cp + build 2017-09-14 12:07:52 -07:00
cache.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
changes.go Windows: support docker diff 2016-10-28 11:06:54 -07:00
checkpoint.go Move names to a more appropriate package. 2017-09-06 12:05:16 -04:00
cluster.go Fix race condition between swarm and libnetwork 2017-05-10 21:16:52 -07:00
commit.go Fixes #29654: take reference to RWLayer while committing/exporting 2017-09-22 09:47:42 +08:00
configs.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
configs_linux.go Add config support to executor backend 2017-05-11 10:08:21 -07:00
configs_unsupported.go Add Windows configs support 2017-05-16 14:25:32 -07:00
configs_windows.go Add Windows configs support 2017-05-16 14:25:32 -07:00
container.go LCOW: WORKDIR correct handling 2017-08-17 15:29:17 -07:00
container_linux.go Remove string checking in API error handling 2017-08-15 16:01:11 -04:00
container_operations.go Remove string checking in API error handling 2017-08-15 16:01:11 -04:00
container_operations_solaris.go Include Endpoint List for Shared Endpoints 2017-07-06 12:19:17 -07:00
container_operations_unix.go Relabel config files. 2017-09-05 18:39:48 -03:00
container_operations_windows.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
container_windows.go Added an apparmorEnabled boolean in the Daemon struct to indicate if AppArmor is enabled or not. It is set in NewDaemon using sysInfo information. 2017-01-30 16:23:23 +01:00
create.go LCOW: WORKDIR correct handling 2017-08-17 15:29:17 -07:00
create_unix.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
create_windows.go Volume refactoring for LCOW 2017-09-14 12:33:31 -07:00
daemon.go Updating moby to correspond to naming convention used in https://github.com/docker/swarmkit/pull/2385 2017-09-26 22:08:10 +00:00
daemon_experimental.go move plugins out of experimental 2016-11-10 15:51:32 -08:00
daemon_linux.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
daemon_linux_test.go use t.Fatal() to output the err message where the values used for formatting 2017-02-23 10:16:22 +08:00
daemon_solaris.go LCOW: Implemented support for docker cp + build 2017-09-14 12:07:52 -07:00
daemon_test.go Store container names in memdb 2017-07-13 12:35:00 -07:00
daemon_unix.go Automatically set may_detach_mounts=1 on startup 2017-09-20 09:57:25 -04:00
daemon_unix_test.go Add ineffassign linter 2017-09-08 18:23:21 -04:00
daemon_unsupported.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
daemon_windows.go Merge pull request #34928 from darrenstahlmsft/HnsRunning 2017-09-27 17:35:08 +02:00
daemon_windows_test.go Ensure Host Network Service exists 2017-09-25 11:07:44 -07:00
debugtrap_unix.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
debugtrap_unsupported.go Spew debugging 2016-11-03 10:05:11 -07:00
debugtrap_windows.go Use event functions from golang.org/x/sys/windows 2017-08-21 12:58:09 +02:00
delete.go Remove string checking in API error handling 2017-08-15 16:01:11 -04:00
delete_test.go Move ErrorContains to an internal package. 2017-08-25 12:04:58 -04:00
dependency.go Add config support to executor backend 2017-05-11 10:08:21 -07:00
disk_usage.go Fix variable shadowing causing LayersSize to be reported as 0 2017-09-12 14:11:11 -03:00
errors.go Fix conflicting container name producint 400 error instead of 409 2017-10-04 20:39:45 +02:00
events.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
events_test.go LCOW: Remove CommonContainer - just Container 2017-06-20 08:55:46 -07:00
exec.go Add interfacer linter 2017-08-24 15:08:26 -04:00
exec_linux.go daemon: also ensureDefaultApparmorProfile in exec path 2017-03-13 15:20:05 +11:00
exec_solaris.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
exec_windows.go LCOW: pass command arguments without extra quoting 2017-06-24 10:23:17 -07:00
export.go Fixes #29654: take reference to RWLayer while committing/exporting 2017-09-22 09:47:42 +08:00
getsize_unix.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
health.go Add deadcode linter 2017-08-21 18:18:50 -04:00
health_test.go Move checkpointing to the Container object 2017-06-23 07:52:32 -07:00
image.go Move to a single tag-store 2017-08-18 17:09:27 -07:00
image_delete.go Move to a single tag-store 2017-08-18 17:09:27 -07:00
image_exporter.go Move to a single tag-store 2017-08-18 17:09:27 -07:00
image_history.go Move to a single tag-store 2017-08-18 17:09:27 -07:00
image_inspect.go Move to a single tag-store 2017-08-18 17:09:27 -07:00
image_pull.go Move to a single tag-store 2017-08-18 17:09:27 -07:00
image_push.go Move to a single tag-store 2017-08-18 17:09:27 -07:00
image_tag.go Move to a single tag-store 2017-08-18 17:09:27 -07:00
images.go Replace uses of filters.Include() with filters.Contains() 2017-09-26 13:39:56 +02:00
import.go Remove string checking in API error handling 2017-08-15 16:01:11 -04:00
info.go Add unconvert linter 2017-08-24 15:08:31 -04:00
info_unix.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
info_unix_test.go Refactor "init" version parsing, and add unit-test 2017-04-08 11:28:37 +02:00
info_windows.go api: types: keep info.SecurityOptions a string slice 2016-11-19 13:21:16 +01:00
inspect.go Remove string checking in API error handling 2017-08-15 16:01:11 -04:00
inspect_solaris.go Move platform specific mount data to Container 2017-06-23 07:22:47 -07:00
inspect_unix.go Move platform specific mount data to Container 2017-06-23 07:22:47 -07:00
inspect_windows.go Move platform specific mount data to Container 2017-06-23 07:22:47 -07:00
keys.go Change root_maxkeys 2016-06-27 10:23:37 -07:00
keys_unsupported.go change minor mistake of spelling 2016-12-20 21:05:19 +08:00
kill.go Optimize some wrong usage and spelling 2017-09-07 09:44:08 +08:00
links.go Remove links when remove container 2017-07-18 12:09:26 +08:00
list.go Replace uses of filters.ToParam(), FromParam() with filters.ToJSON(), FromJSON() 2017-09-26 13:59:45 +02:00
list_unix.go stop grabbing container locks during ps 2017-06-23 07:52:31 -07:00
list_windows.go stop grabbing container locks during ps 2017-06-23 07:52:31 -07:00
logdrivers_linux.go added logentries driver 2016-10-06 22:48:53 -03:00
logdrivers_windows.go Windows: Enable fluentd logdriver 2016-11-08 19:54:57 -08:00
logs.go Remove string checking in API error handling 2017-08-15 16:01:11 -04:00
logs_test.go Add engine-api types to docker 2016-09-07 11:05:58 -07:00
metrics.go Add gosimple linter 2017-09-12 12:09:59 -04:00
metrics_unix.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
metrics_unsupported.go Add support for metrics plugins 2017-05-12 00:30:09 -04:00
monitor.go Fix golint errors. 2017-08-18 14:23:44 -04:00
monitor_linux.go Adding postRunProcessing infrastructure for hanlding Windows Update. 2016-04-06 14:03:05 -07:00
monitor_solaris.go Get the Docker Engine to build clean on Solaris 2016-05-23 16:37:12 -07:00
monitor_windows.go Update Windows and LCOW to use v1.0.0 runtime-spec 2017-08-21 15:19:31 -07:00
mounts.go Fix issue backporting mount spec to pre-1.13 obj 2017-05-11 12:31:53 -04:00
names.go Fix conflicting container name producint 400 error instead of 409 2017-10-04 20:39:45 +02:00
network.go Fixing panic when sandbox is nil 2017-09-29 09:23:06 -07:00
oci_linux.go Merge pull request #34252 from Microsoft/akagup/lcow-remotefs-sandbox 2017-09-15 16:49:48 -07:00
oci_solaris.go LCOW: Implemented support for docker cp + build 2017-09-14 12:07:52 -07:00
oci_windows.go Merge pull request #34252 from Microsoft/akagup/lcow-remotefs-sandbox 2017-09-15 16:49:48 -07:00
pause.go Remove string checking in API error handling 2017-08-15 16:01:11 -04:00
prune.go Replace uses of filters.Include() with filters.Contains() 2017-09-26 13:39:56 +02:00
reload.go Implement none, private, and shareable ipc modes 2017-08-14 10:50:39 +03:00
reload_test.go Merge pull request #34495 from ripcurld0/registry_mirror_json 2017-09-18 21:59:14 -07:00
rename.go Remove string checking in API error handling 2017-08-15 16:01:11 -04:00
resize.go Remove string checking in API error handling 2017-08-15 16:01:11 -04:00
restart.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
search.go Replace uses of filters.ToParam(), FromParam() with filters.ToJSON(), FromJSON() 2017-09-26 13:59:45 +02:00
search_test.go Remove redundant format 2016-12-27 21:46:52 +08:00
seccomp_disabled.go Replace old oci specs import with runtime-specs 2016-08-17 09:38:34 -07:00
seccomp_linux.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
seccomp_unsupported.go Fix seccomp output in docker info 2016-07-08 17:26:42 -07:00
secrets.go Update logrus to v1.0.1 2017-07-31 13:16:46 -07:00
secrets_linux.go secrets: secret management for swarm 2016-11-09 14:27:43 -05:00
secrets_unsupported.go Add Windows secrets support 2017-05-16 11:30:06 -07:00
secrets_windows.go Add Windows secrets support 2017-05-16 11:30:06 -07:00
selinux_linux.go Switch to using opencontainers/selinux for selinux bindings 2017-04-24 21:29:47 +02:00
selinux_unsupported.go Rename daemon/utils_*.go to selinux 2015-11-12 15:48:41 -08:00
start.go LCOW: Implemented support for docker cp + build 2017-09-14 12:07:52 -07:00
start_unix.go Remove string checking in API error handling 2017-08-15 16:01:11 -04:00
start_windows.go Update Windows and LCOW to use v1.0.0 runtime-spec 2017-08-21 15:19:31 -07:00
stats.go Send "Name" and "ID" when stating stopped containers 2017-02-09 09:46:59 +08:00
stats_collector.go Extract daemon statsCollector to its own package 2017-01-04 18:18:30 +01:00
stats_unix.go Remove string checking in API error handling 2017-08-15 16:01:11 -04:00
stats_windows.go Windows: stats support 2016-09-16 11:56:15 -07:00
stop.go Optimize some wrong usage and spelling 2017-09-07 09:44:08 +08:00
top_unix.go Add gosimple linter 2017-09-12 12:09:59 -04:00
top_unix_test.go Fixing issue of docker top command failure when dealing with -m option 2017-03-10 02:50:21 +00:00
top_windows.go Convert ContainerTopOKResponse from swagger spec. 2017-01-03 11:47:47 -05:00
trustkey.go Remove libtrust dep from api 2017-09-06 12:05:19 -04:00
trustkey_test.go Remove libtrust dep from api 2017-09-06 12:05:19 -04:00
unpause.go remove running judgement when unpause container 2016-08-29 10:16:18 +08:00
update.go Fix golint errors. 2017-08-18 14:23:44 -04:00
update_linux.go Add --cpus support for docker update 2017-04-06 15:40:12 -07:00
update_solaris.go Add engine-api types to docker 2016-09-07 11:05:58 -07:00
update_windows.go Add engine-api types to docker 2016-09-07 11:05:58 -07:00
volumes.go Set selinux label on local volumes from mounts API 2017-09-19 10:46:38 -04:00
volumes_unit_test.go Volume refactoring for LCOW 2017-09-14 12:33:31 -07:00
volumes_unix.go avoid saving container state to disk before daemon.Register 2017-06-23 07:52:34 -07:00
volumes_unix_test.go Spelling fixes 2017-07-03 13:13:09 -07:00
volumes_windows.go Partial refactor of UID/GID usage to use a unified struct. 2017-06-07 11:44:33 -04:00
wait.go Update ContainerWait API 2017-05-16 15:11:39 -07:00
workdir.go Remove error return from RootPair 2017-06-07 11:45:33 -04:00