daemon.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. package errors
  2. // This file contains all of the errors that can be generated from the
  3. // docker/daemon component.
  4. import (
  5. "net/http"
  6. "github.com/docker/distribution/registry/api/errcode"
  7. )
  8. var (
  9. // ErrorCodeNoSuchContainer is generated when we look for a container by
  10. // name or ID and we can't find it.
  11. ErrorCodeNoSuchContainer = errcode.Register(errGroup, errcode.ErrorDescriptor{
  12. Value: "NOSUCHCONTAINER",
  13. Message: "no such id: %s",
  14. Description: "The specified container can not be found",
  15. HTTPStatusCode: http.StatusNotFound,
  16. })
  17. // ErrorCodeUnregisteredContainer is generated when we try to load
  18. // a storage driver for an unregistered container
  19. ErrorCodeUnregisteredContainer = errcode.Register(errGroup, errcode.ErrorDescriptor{
  20. Value: "UNREGISTEREDCONTAINER",
  21. Message: "Can't load storage driver for unregistered container %s",
  22. HTTPStatusCode: http.StatusInternalServerError,
  23. })
  24. // ErrorCodeContainerBeingRemoved is generated when an attempt to start
  25. // a container is made but its in the process of being removed, or is dead.
  26. ErrorCodeContainerBeingRemoved = errcode.Register(errGroup, errcode.ErrorDescriptor{
  27. Value: "CONTAINERBEINGREMOVED",
  28. Message: "Container is marked for removal and cannot be started.",
  29. HTTPStatusCode: http.StatusInternalServerError,
  30. })
  31. // ErrorCodeUnpauseContainer is generated when we attempt to stop a
  32. // container but its paused.
  33. ErrorCodeUnpauseContainer = errcode.Register(errGroup, errcode.ErrorDescriptor{
  34. Value: "UNPAUSECONTAINER",
  35. Message: "Container %s is paused. Unpause the container before stopping",
  36. HTTPStatusCode: http.StatusInternalServerError,
  37. })
  38. // ErrorCodeAlreadyPaused is generated when we attempt to pause a
  39. // container when its already paused.
  40. ErrorCodeAlreadyPaused = errcode.Register(errGroup, errcode.ErrorDescriptor{
  41. Value: "ALREADYPAUSED",
  42. Message: "Container %s is already paused",
  43. HTTPStatusCode: http.StatusInternalServerError,
  44. })
  45. // ErrorCodeNotPaused is generated when we attempt to unpause a
  46. // container when its not paused.
  47. ErrorCodeNotPaused = errcode.Register(errGroup, errcode.ErrorDescriptor{
  48. Value: "NOTPAUSED",
  49. Message: "Container %s is not paused",
  50. HTTPStatusCode: http.StatusInternalServerError,
  51. })
  52. // ErrorCodeImageUnregContainer is generated when we attempt to get the
  53. // image of an unknown/unregistered container.
  54. ErrorCodeImageUnregContainer = errcode.Register(errGroup, errcode.ErrorDescriptor{
  55. Value: "IMAGEUNREGCONTAINER",
  56. Message: "Can't get image of unregistered container",
  57. HTTPStatusCode: http.StatusInternalServerError,
  58. })
  59. // ErrorCodeEmptyID is generated when an ID is the emptry string.
  60. ErrorCodeEmptyID = errcode.Register(errGroup, errcode.ErrorDescriptor{
  61. Value: "EMPTYID",
  62. Message: "Invalid empty id",
  63. HTTPStatusCode: http.StatusInternalServerError,
  64. })
  65. // ErrorCodeLoggingFactory is generated when we could not load the
  66. // log driver.
  67. ErrorCodeLoggingFactory = errcode.Register(errGroup, errcode.ErrorDescriptor{
  68. Value: "LOGGINGFACTORY",
  69. Message: "Failed to get logging factory: %v",
  70. HTTPStatusCode: http.StatusInternalServerError,
  71. })
  72. // ErrorCodeInitLogger is generated when we could not initialize
  73. // the logging driver.
  74. ErrorCodeInitLogger = errcode.Register(errGroup, errcode.ErrorDescriptor{
  75. Value: "INITLOGGER",
  76. Message: "Failed to initialize logging driver: %v",
  77. HTTPStatusCode: http.StatusInternalServerError,
  78. })
  79. // ErrorCodeNotRunning is generated when we need to verify that
  80. // a container is running, but its not.
  81. ErrorCodeNotRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{
  82. Value: "NOTRUNNING",
  83. Message: "Container %s is not running",
  84. HTTPStatusCode: http.StatusInternalServerError,
  85. })
  86. // ErrorCodeLinkNotRunning is generated when we try to link to a
  87. // container that is not running.
  88. ErrorCodeLinkNotRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{
  89. Value: "LINKNOTRUNNING",
  90. Message: "Cannot link to a non running container: %s AS %s",
  91. HTTPStatusCode: http.StatusInternalServerError,
  92. })
  93. // ErrorCodeDeviceInfo is generated when there is an error while trying
  94. // to get info about a custom device.
  95. // container that is not running.
  96. ErrorCodeDeviceInfo = errcode.Register(errGroup, errcode.ErrorDescriptor{
  97. Value: "DEVICEINFO",
  98. Message: "error gathering device information while adding custom device %q: %s",
  99. HTTPStatusCode: http.StatusInternalServerError,
  100. })
  101. // ErrorCodeEmptyEndpoint is generated when the endpoint for a port
  102. // map is nil.
  103. ErrorCodeEmptyEndpoint = errcode.Register(errGroup, errcode.ErrorDescriptor{
  104. Value: "EMPTYENDPOINT",
  105. Message: "invalid endpoint while building port map info",
  106. HTTPStatusCode: http.StatusInternalServerError,
  107. })
  108. // ErrorCodeEmptyNetwork is generated when the networkSettings for a port
  109. // map is nil.
  110. ErrorCodeEmptyNetwork = errcode.Register(errGroup, errcode.ErrorDescriptor{
  111. Value: "EMPTYNETWORK",
  112. Message: "invalid networksettings while building port map info",
  113. HTTPStatusCode: http.StatusInternalServerError,
  114. })
  115. // ErrorCodeParsingPort is generated when there is an error parsing
  116. // a "port" string.
  117. ErrorCodeParsingPort = errcode.Register(errGroup, errcode.ErrorDescriptor{
  118. Value: "PARSINGPORT",
  119. Message: "Error parsing Port value(%v):%v",
  120. HTTPStatusCode: http.StatusInternalServerError,
  121. })
  122. // ErrorCodeNoSandbox is generated when we can't find the specified
  123. // sandbox(network) by ID.
  124. ErrorCodeNoSandbox = errcode.Register(errGroup, errcode.ErrorDescriptor{
  125. Value: "NOSANDBOX",
  126. Message: "error locating sandbox id %s: %v",
  127. HTTPStatusCode: http.StatusInternalServerError,
  128. })
  129. // ErrorCodeNetworkUpdate is generated when there is an error while
  130. // trying update a network/sandbox config.
  131. ErrorCodeNetworkUpdate = errcode.Register(errGroup, errcode.ErrorDescriptor{
  132. Value: "NETWORKUPDATE",
  133. Message: "Update network failed: %v",
  134. HTTPStatusCode: http.StatusInternalServerError,
  135. })
  136. // ErrorCodeNetworkRefresh is generated when there is an error while
  137. // trying refresh a network/sandbox config.
  138. ErrorCodeNetworkRefresh = errcode.Register(errGroup, errcode.ErrorDescriptor{
  139. Value: "NETWORKREFRESH",
  140. Message: "Update network failed: Failure in refresh sandbox %s: %v",
  141. HTTPStatusCode: http.StatusInternalServerError,
  142. })
  143. // ErrorCodeHostPort is generated when there was an error while trying
  144. // to parse a "host/por" string.
  145. ErrorCodeHostPort = errcode.Register(errGroup, errcode.ErrorDescriptor{
  146. Value: "HOSTPORT",
  147. Message: "Error parsing HostPort value(%s):%v",
  148. HTTPStatusCode: http.StatusInternalServerError,
  149. })
  150. // ErrorCodeNetworkConflict is generated when we try to public a service
  151. // in network mode.
  152. ErrorCodeNetworkConflict = errcode.Register(errGroup, errcode.ErrorDescriptor{
  153. Value: "NETWORKCONFLICT",
  154. Message: "conflicting options: publishing a service and network mode",
  155. HTTPStatusCode: http.StatusConflict,
  156. })
  157. // ErrorCodeJoinInfo is generated when we failed to update a container's
  158. // join info.
  159. ErrorCodeJoinInfo = errcode.Register(errGroup, errcode.ErrorDescriptor{
  160. Value: "JOININFO",
  161. Message: "Updating join info failed: %v",
  162. HTTPStatusCode: http.StatusInternalServerError,
  163. })
  164. // ErrorCodeIPCRunning is generated when we try to join a container's
  165. // IPC but its running.
  166. ErrorCodeIPCRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{
  167. Value: "IPCRUNNING",
  168. Message: "cannot join IPC of a non running container: %s",
  169. HTTPStatusCode: http.StatusInternalServerError,
  170. })
  171. // ErrorCodeNotADir is generated when we try to create a directory
  172. // but the path isn't a dir.
  173. ErrorCodeNotADir = errcode.Register(errGroup, errcode.ErrorDescriptor{
  174. Value: "NOTADIR",
  175. Message: "Cannot mkdir: %s is not a directory",
  176. HTTPStatusCode: http.StatusInternalServerError,
  177. })
  178. // ErrorCodeParseContainer is generated when the reference to a
  179. // container doesn't include a ":" (another container).
  180. ErrorCodeParseContainer = errcode.Register(errGroup, errcode.ErrorDescriptor{
  181. Value: "PARSECONTAINER",
  182. Message: "no container specified to join network",
  183. HTTPStatusCode: http.StatusInternalServerError,
  184. })
  185. // ErrorCodeJoinSelf is generated when we try to network to ourselves.
  186. ErrorCodeJoinSelf = errcode.Register(errGroup, errcode.ErrorDescriptor{
  187. Value: "JOINSELF",
  188. Message: "cannot join own network",
  189. HTTPStatusCode: http.StatusInternalServerError,
  190. })
  191. // ErrorCodeJoinRunning is generated when we try to network to ourselves.
  192. ErrorCodeJoinRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{
  193. Value: "JOINRUNNING",
  194. Message: "cannot join network of a non running container: %s",
  195. HTTPStatusCode: http.StatusInternalServerError,
  196. })
  197. // ErrorCodeModeNotContainer is generated when we try to network to
  198. // another container but the mode isn't 'container'.
  199. ErrorCodeModeNotContainer = errcode.Register(errGroup, errcode.ErrorDescriptor{
  200. Value: "MODENOTCONTAINER",
  201. Message: "network mode not set to container",
  202. HTTPStatusCode: http.StatusInternalServerError,
  203. })
  204. // ErrorCodeRemovingVolume is generated when we try remove a mount
  205. // point (volume) but fail.
  206. ErrorCodeRemovingVolume = errcode.Register(errGroup, errcode.ErrorDescriptor{
  207. Value: "REMOVINGVOLUME",
  208. Message: "Error removing volumes:\n%v",
  209. HTTPStatusCode: http.StatusInternalServerError,
  210. })
  211. // ErrorCodeInvalidNetworkMode is generated when an invalid network
  212. // mode value is specified.
  213. ErrorCodeInvalidNetworkMode = errcode.Register(errGroup, errcode.ErrorDescriptor{
  214. Value: "INVALIDNETWORKMODE",
  215. Message: "invalid network mode: %s",
  216. HTTPStatusCode: http.StatusInternalServerError,
  217. })
  218. // ErrorCodeGetGraph is generated when there was an error while
  219. // trying to find a graph/image.
  220. ErrorCodeGetGraph = errcode.Register(errGroup, errcode.ErrorDescriptor{
  221. Value: "GETGRAPH",
  222. Message: "Failed to graph.Get on ImageID %s - %s",
  223. HTTPStatusCode: http.StatusInternalServerError,
  224. })
  225. // ErrorCodeGetLayer is generated when there was an error while
  226. // trying to retrieve a particular layer of an image.
  227. ErrorCodeGetLayer = errcode.Register(errGroup, errcode.ErrorDescriptor{
  228. Value: "GETLAYER",
  229. Message: "Failed to get layer path from graphdriver %s for ImageID %s - %s",
  230. HTTPStatusCode: http.StatusInternalServerError,
  231. })
  232. // ErrorCodePutLayer is generated when there was an error while
  233. // trying to 'put' a particular layer of an image.
  234. ErrorCodePutLayer = errcode.Register(errGroup, errcode.ErrorDescriptor{
  235. Value: "PUTLAYER",
  236. Message: "Failed to put layer path from graphdriver %s for ImageID %s - %s",
  237. HTTPStatusCode: http.StatusInternalServerError,
  238. })
  239. // ErrorCodeGetLayerMetadata is generated when there was an error while
  240. // trying to retrieve the metadata of a layer of an image.
  241. ErrorCodeGetLayerMetadata = errcode.Register(errGroup, errcode.ErrorDescriptor{
  242. Value: "GETLAYERMETADATA",
  243. Message: "Failed to get layer metadata - %s",
  244. HTTPStatusCode: http.StatusInternalServerError,
  245. })
  246. // ErrorCodeEmptyConfig is generated when the input config data
  247. // is empty.
  248. ErrorCodeEmptyConfig = errcode.Register(errGroup, errcode.ErrorDescriptor{
  249. Value: "EMPTYCONFIG",
  250. Message: "Config cannot be empty in order to create a container",
  251. HTTPStatusCode: http.StatusInternalServerError,
  252. })
  253. // ErrorCodeNoSuchImageHash is generated when we can't find the
  254. // specified image by its hash
  255. ErrorCodeNoSuchImageHash = errcode.Register(errGroup, errcode.ErrorDescriptor{
  256. Value: "NOSUCHIMAGEHASH",
  257. Message: "No such image: %s",
  258. HTTPStatusCode: http.StatusNotFound,
  259. })
  260. // ErrorCodeNoSuchImageTag is generated when we can't find the
  261. // specified image byt its name/tag.
  262. ErrorCodeNoSuchImageTag = errcode.Register(errGroup, errcode.ErrorDescriptor{
  263. Value: "NOSUCHIMAGETAG",
  264. Message: "No such image: %s:%s",
  265. HTTPStatusCode: http.StatusNotFound,
  266. })
  267. // ErrorCodeMountOverFile is generated when we try to mount a volume
  268. // over an existing file (but not a dir).
  269. ErrorCodeMountOverFile = errcode.Register(errGroup, errcode.ErrorDescriptor{
  270. Value: "MOUNTOVERFILE",
  271. Message: "cannot mount volume over existing file, file exists %s",
  272. HTTPStatusCode: http.StatusInternalServerError,
  273. })
  274. // ErrorCodeMountSetup is generated when we can't define a mount point
  275. // due to the source and destination are defined.
  276. ErrorCodeMountSetup = errcode.Register(errGroup, errcode.ErrorDescriptor{
  277. Value: "MOUNTSETUP",
  278. Message: "Unable to setup mount point, neither source nor volume defined",
  279. HTTPStatusCode: http.StatusInternalServerError,
  280. })
  281. // ErrorCodeVolumeInvalidMode is generated when we the mode of a volume
  282. // mount is invalid.
  283. ErrorCodeVolumeInvalidMode = errcode.Register(errGroup, errcode.ErrorDescriptor{
  284. Value: "VOLUMEINVALIDMODE",
  285. Message: "invalid mode for volumes-from: %s",
  286. HTTPStatusCode: http.StatusInternalServerError,
  287. })
  288. // ErrorCodeVolumeInvalid is generated when the format fo the
  289. // volume specification isn't valid.
  290. ErrorCodeVolumeInvalid = errcode.Register(errGroup, errcode.ErrorDescriptor{
  291. Value: "VOLUMEINVALID",
  292. Message: "Invalid volume specification: %s",
  293. HTTPStatusCode: http.StatusInternalServerError,
  294. })
  295. // ErrorCodeVolumeAbs is generated when path to a volume isn't absolute.
  296. ErrorCodeVolumeAbs = errcode.Register(errGroup, errcode.ErrorDescriptor{
  297. Value: "VOLUMEABS",
  298. Message: "Invalid volume destination path: %s mount path must be absolute.",
  299. HTTPStatusCode: http.StatusInternalServerError,
  300. })
  301. // ErrorCodeVolumeFromBlank is generated when path to a volume is blank.
  302. ErrorCodeVolumeFromBlank = errcode.Register(errGroup, errcode.ErrorDescriptor{
  303. Value: "VOLUMEFROMBLANK",
  304. Message: "malformed volumes-from specification: %s",
  305. HTTPStatusCode: http.StatusInternalServerError,
  306. })
  307. // ErrorCodeVolumeMode is generated when 'mode' for a volume
  308. // isn't a valid.
  309. ErrorCodeVolumeMode = errcode.Register(errGroup, errcode.ErrorDescriptor{
  310. Value: "VOLUMEMODE",
  311. Message: "invalid mode for volumes-from: %s",
  312. HTTPStatusCode: http.StatusInternalServerError,
  313. })
  314. // ErrorCodeVolumeDup is generated when we try to mount two volumes
  315. // to the same path.
  316. ErrorCodeVolumeDup = errcode.Register(errGroup, errcode.ErrorDescriptor{
  317. Value: "VOLUMEDUP",
  318. Message: "Duplicate bind mount %s",
  319. HTTPStatusCode: http.StatusInternalServerError,
  320. })
  321. // ErrorCodeCantUnpause is generated when there's an error while trying
  322. // to unpause a container.
  323. ErrorCodeCantUnpause = errcode.Register(errGroup, errcode.ErrorDescriptor{
  324. Value: "CANTUNPAUSE",
  325. Message: "Cannot unpause container %s: %s",
  326. HTTPStatusCode: http.StatusInternalServerError,
  327. })
  328. // ErrorCodePSError is generated when trying to run 'ps'.
  329. ErrorCodePSError = errcode.Register(errGroup, errcode.ErrorDescriptor{
  330. Value: "PSError",
  331. Message: "Error running ps: %s",
  332. HTTPStatusCode: http.StatusInternalServerError,
  333. })
  334. // ErrorCodeNoPID is generated when looking for the PID field in the
  335. // ps output.
  336. ErrorCodeNoPID = errcode.Register(errGroup, errcode.ErrorDescriptor{
  337. Value: "NOPID",
  338. Message: "Couldn't find PID field in ps output",
  339. HTTPStatusCode: http.StatusInternalServerError,
  340. })
  341. // ErrorCodeBadPID is generated when we can't convert a PID to an int.
  342. ErrorCodeBadPID = errcode.Register(errGroup, errcode.ErrorDescriptor{
  343. Value: "BADPID",
  344. Message: "Unexpected pid '%s': %s",
  345. HTTPStatusCode: http.StatusInternalServerError,
  346. })
  347. // ErrorCodeNoTop is generated when we try to run 'top' but can't
  348. // because we're on windows.
  349. ErrorCodeNoTop = errcode.Register(errGroup, errcode.ErrorDescriptor{
  350. Value: "NOTOP",
  351. Message: "Top is not supported on Windows",
  352. HTTPStatusCode: http.StatusInternalServerError,
  353. })
  354. // ErrorCodeStopped is generated when we try to stop a container
  355. // that is already stopped.
  356. ErrorCodeStopped = errcode.Register(errGroup, errcode.ErrorDescriptor{
  357. Value: "STOPPED",
  358. Message: "Container already stopped",
  359. HTTPStatusCode: http.StatusNotModified,
  360. })
  361. // ErrorCodeCantStop is generated when we try to stop a container
  362. // but failed for some reason.
  363. ErrorCodeCantStop = errcode.Register(errGroup, errcode.ErrorDescriptor{
  364. Value: "CANTSTOP",
  365. Message: "Cannot stop container %s: %s\n",
  366. HTTPStatusCode: http.StatusInternalServerError,
  367. })
  368. // ErrorCodeBadCPUFields is generated the number of CPU fields is
  369. // less than 8.
  370. ErrorCodeBadCPUFields = errcode.Register(errGroup, errcode.ErrorDescriptor{
  371. Value: "BADCPUFIELDS",
  372. Message: "invalid number of cpu fields",
  373. HTTPStatusCode: http.StatusInternalServerError,
  374. })
  375. // ErrorCodeBadCPUInt is generated the CPU field can't be parsed as an int.
  376. ErrorCodeBadCPUInt = errcode.Register(errGroup, errcode.ErrorDescriptor{
  377. Value: "BADCPUINT",
  378. Message: "Unable to convert value %s to int: %s",
  379. HTTPStatusCode: http.StatusInternalServerError,
  380. })
  381. // ErrorCodeBadStatFormat is generated the output of the stat info
  382. // isn't parseable.
  383. ErrorCodeBadStatFormat = errcode.Register(errGroup, errcode.ErrorDescriptor{
  384. Value: "BADSTATFORMAT",
  385. Message: "invalid stat format",
  386. HTTPStatusCode: http.StatusInternalServerError,
  387. })
  388. // ErrorCodeTimedOut is generated when a timer expires.
  389. ErrorCodeTimedOut = errcode.Register(errGroup, errcode.ErrorDescriptor{
  390. Value: "TIMEDOUT",
  391. Message: "Timed out: %v",
  392. HTTPStatusCode: http.StatusInternalServerError,
  393. })
  394. // ErrorCodeAlreadyRemoving is generated when we try to remove a
  395. // container that is already being removed.
  396. ErrorCodeAlreadyRemoving = errcode.Register(errGroup, errcode.ErrorDescriptor{
  397. Value: "ALREADYREMOVING",
  398. Message: "Status is already RemovalInProgress",
  399. HTTPStatusCode: http.StatusInternalServerError,
  400. })
  401. // ErrorCodeStartPaused is generated when we start a paused container.
  402. ErrorCodeStartPaused = errcode.Register(errGroup, errcode.ErrorDescriptor{
  403. Value: "STARTPAUSED",
  404. Message: "Cannot start a paused container, try unpause instead.",
  405. HTTPStatusCode: http.StatusInternalServerError,
  406. })
  407. // ErrorCodeAlreadyStarted is generated when we try to start a container
  408. // that is already running.
  409. ErrorCodeAlreadyStarted = errcode.Register(errGroup, errcode.ErrorDescriptor{
  410. Value: "ALREADYSTARTED",
  411. Message: "Container already started",
  412. HTTPStatusCode: http.StatusNotModified,
  413. })
  414. // ErrorCodeHostConfigStart is generated when a HostConfig is passed
  415. // into the start command.
  416. ErrorCodeHostConfigStart = errcode.Register(errGroup, errcode.ErrorDescriptor{
  417. Value: "HOSTCONFIGSTART",
  418. Message: "Supplying a hostconfig on start is not supported. It should be supplied on create",
  419. HTTPStatusCode: http.StatusInternalServerError,
  420. })
  421. // ErrorCodeCantStart is generated when an error occurred while
  422. // trying to start a container.
  423. ErrorCodeCantStart = errcode.Register(errGroup, errcode.ErrorDescriptor{
  424. Value: "CANTSTART",
  425. Message: "Cannot start container %s: %s",
  426. HTTPStatusCode: http.StatusInternalServerError,
  427. })
  428. )