Commit Graph

56 Commits

Author SHA1 Message Date
7e3fc728ee container: container_unix: remove unused func
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Upstream-commit: 0e9769ab62ec15d56541dfbbe72316630a98b6e2
Component: engine
2016-02-29 16:12:02 +01:00
b2ac99b3fa Remove static errors from errors package.
Moving all strings to the errors package wasn't a good idea after all.

Our custom implementation of Go errors predates everything that's nice
and good about working with errors in Go. Take as an example what we
have to do to get an error message:

```go
func GetErrorMessage(err error) string {
	switch err.(type) {
	case errcode.Error:
		e, _ := err.(errcode.Error)
		return e.Message

	case errcode.ErrorCode:
		ec, _ := err.(errcode.ErrorCode)
		return ec.Message()

	default:
		return err.Error()
	}
}
```

This goes against every good practice for Go development. The language already provides a simple, intuitive and standard way to get error messages, that is calling the `Error()` method from an error. Reinventing the error interface is a mistake.

Our custom implementation also makes very hard to reason about errors, another nice thing about Go. I found several (>10) error declarations that we don't use anywhere. This is a clear sign about how little we know about the errors we return. I also found several error usages where the number of arguments was different than the parameters declared in the error, another clear example of how difficult is to reason about errors.

Moreover, our custom implementation didn't really make easier for people to return custom HTTP status code depending on the errors. Again, it's hard to reason about when to set custom codes and how. Take an example what we have to do to extract the message and status code from an error before returning a response from the API:

```go
	switch err.(type) {
	case errcode.ErrorCode:
		daError, _ := err.(errcode.ErrorCode)
		statusCode = daError.Descriptor().HTTPStatusCode
		errMsg = daError.Message()

	case errcode.Error:
		// For reference, if you're looking for a particular error
		// then you can do something like :
		//   import ( derr "github.com/docker/docker/errors" )
		//   if daError.ErrorCode() == derr.ErrorCodeNoSuchContainer { ... }

		daError, _ := err.(errcode.Error)
		statusCode = daError.ErrorCode().Descriptor().HTTPStatusCode
		errMsg = daError.Message

	default:
		// This part of will be removed once we've
		// converted everything over to use the errcode package

		// FIXME: this is brittle and should not be necessary.
		// If we need to differentiate between different possible error types,
		// we should create appropriate error types with clearly defined meaning
		errStr := strings.ToLower(err.Error())
		for keyword, status := range map[string]int{
			"not found":             http.StatusNotFound,
			"no such":               http.StatusNotFound,
			"bad parameter":         http.StatusBadRequest,
			"conflict":              http.StatusConflict,
			"impossible":            http.StatusNotAcceptable,
			"wrong login/password":  http.StatusUnauthorized,
			"hasn't been activated": http.StatusForbidden,
		} {
			if strings.Contains(errStr, keyword) {
				statusCode = status
				break
			}
		}
	}
```

You can notice two things in that code:

1. We have to explain how errors work, because our implementation goes against how easy to use Go errors are.
2. At no moment we arrived to remove that `switch` statement that was the original reason to use our custom implementation.

This change removes all our status errors from the errors package and puts them back in their specific contexts.
IT puts the messages back with their contexts. That way, we know right away when errors used and how to generate their messages.
It uses custom interfaces to reason about errors. Errors that need to response with a custom status code MUST implementent this simple interface:

```go
type errorWithStatus interface {
	HTTPErrorStatusCode() int
}
```

This interface is very straightforward to implement. It also preserves Go errors real behavior, getting the message is as simple as using the `Error()` method.

I included helper functions to generate errors that use custom status code in `errors/errors.go`.

By doing this, we remove the hard dependency we have eeverywhere to our custom errors package. Yes, you can use it as a helper to generate error, but it's still very easy to generate errors without it.

Please, read this fantastic blog post about errors in Go: http://dave.cheney.net/2014/12/24/inspecting-errors

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: a793564b2591035aec5412fbcbcccf220c773a4c
Component: engine
2016-02-26 15:49:09 -05:00
f153cf13ed Update RestartPolicy of container
Add `--restart` flag for `update` command, so we can change restart
policy for a container no matter it's running or stopped.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
Upstream-commit: ff3ea4c90f2ede5cccc6b49c4d2aad7201c91a4c
Component: engine
2016-02-20 17:06:32 +08:00
6d4102dcb8 Merge pull request #20133 from mlaventure/dont-bind-mount-mqueue
Prevent mqueue from implicitely becoming a bind mount with --ipc=host
Upstream-commit: 0b4a7fb06d4b77265831cee1508aad9fbeddb7a2
Component: engine
2016-02-09 19:55:57 -05:00
7d8fc9149c Merge pull request #19985 from Microsoft/CombineSetupWorkingDir
Combine SetupWorkingDirectory for Linux and Windows
Upstream-commit: d6870238e329e43d2df291a5f82d27929f9a192d
Component: engine
2016-02-09 15:18:49 -08:00
24558a48dd Prevent mqueue from implicitely becoming a bind mount with --ipc=host
Currently, when running a container with --ipc=host, if /dev/mqueue is
a standard directory on the hos the daemon will bind mount it allowing
the container to create/modify files on the host.

This commit forces /dev/mqueue to always be of type mqueue except when
the user explicitely requested something to be bind mounted to
/dev/mqueue.

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
Upstream-commit: f7d4abdc00d521509995da1070215c808fe0fd9c
Component: engine
2016-02-09 14:16:08 -08:00
2fc41c0b8b Combine SetupWorkingDirectory for Linux and Windows
Signed-off-by: Darren Stahl <darst@microsoft.com>
Upstream-commit: 6791230320fa9f8ae9df3e90d5c52d85621828a0
Component: engine
2016-02-05 10:27:10 -08:00
1a4e7d1b20 Make mqueue container specific
mqueue can not be mounted on the host os and then shared into the container.
There is only one mqueue per mount namespace, so current code ends up leaking
the /dev/mqueue from the host into ALL containers.  Since SELinux changes the
label of the mqueue, only the last container is able to use the mqueue, all
other containers will get a permission denied.  If you don't have SELinux protections
sharing of the /dev/mqueue allows one container to interact in potentially hostile
ways with other containers.

Signed-off-by: Dan Walsh <dwalsh@redhat.com>
Upstream-commit: ba38d58659cc155aebf89a2ea4cfc3cd7ba04a64
Component: engine
2016-02-05 16:50:35 +01:00
93226572ef Lock container when set state to restarting
After exec driver run, container lock is lost, so we should lock
container when changing its state to `restarting`

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
Upstream-commit: 155714c59650a7b9b8f890f4d20c83ea9b80206b
Component: engine
2016-02-02 19:50:06 +08:00
342ab710cd Signed-off-by: John Howard <jhoward@microsoft.com>
Revert "Combine SetupWorkingDirectory for Linux and Windows"

This reverts commit ec31741ca186278ea60faf49f85087c493e78806.
Upstream-commit: 54320d8d187d8b33be4fd33cfb3f8e486c6c8d90
Component: engine
2016-01-29 20:49:39 -08:00
88afeb1908 Combine SetupWorkingDirectory for Linux and Windows
Signed-off-by: Darren Stahl <darst@microsoft.com>
Upstream-commit: ec31741ca186278ea60faf49f85087c493e78806
Component: engine
2016-01-27 16:17:35 -08:00
4c547f393d Merge pull request #19722 from WeiZhang555/exec-restarting
Forbid exec a restarting container
Upstream-commit: 0ae94303b89a9648f26b599617a9d78ee5284a4c
Component: engine
2016-01-27 11:43:43 +08:00
1083d494cd Forbid exec a restarting container
Currently if we exec a restarting container, client will fail silently,
and daemon will print error that container can't be found which is not a
very meaningful prompt to user.

This commit will stop user from exec a restarting container and gives
more explicit error message.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
Upstream-commit: 1d2208fed90da9ab72ded3b1c65bb2a71b66ce93
Component: engine
2016-01-27 10:05:06 +08:00
eed5e0f1c7 Merge pull request #19705 from mavenugo/18222
Vendor libnetwork v0.6.0-rc4 & corresponding changes in engine for port-map sandobx handling.
Upstream-commit: 269a6d7d3656fe7edf7cb630125ee4664dd24c78
Component: engine
2016-01-26 09:16:57 -08:00
4edafc3bc1 *: purge dockerinit from source code
dockerinit has been around for a very long time. It was originally used
as a way for us to do configuration for LXC containers once the
container had started. LXC is no longer supported, and /.dockerinit has
been dead code for quite a while. This removes all code and references
in code to dockerinit.

Signed-off-by: Aleksa Sarai <asarai@suse.com>
Upstream-commit: 4357ed4a7363a1032edf93cf03232953c805184f
Component: engine
2016-01-26 23:47:02 +11:00
578fa2d8c0 Move port-mapping ownership closer to Sandbox (from Endpoint)
https://github.com/docker/libnetwork/pull/810 provides the more complete
solution for moving the Port-mapping ownership away from endpoint and
into Sandbox. But, this PR makes the best use of existing libnetwork
design and get a step closer to the gaol.

Signed-off-by: Madhu Venugopal <madhu@docker.com>
Upstream-commit: e38463b2779f455b4173171d5a1fdb115180a7e9
Component: engine
2016-01-26 03:59:03 -08:00
6f75e7937c Save endpoint config only if endpoint creation succeeds
- Currently it is being save upfront...

Signed-off-by: Alessandro Boch <aboch@docker.com>
Upstream-commit: 733245b2e7517b88cdfb188f9d8418f29bca6338
Component: engine
2016-01-25 13:43:32 -08:00
4f27e3ae36 IT for service/network name with '.', corrected libnetwork flag for DNS
Signed-off-by: Santhosh Manohar <santhosh@docker.com>
Upstream-commit: da9eadb06669b7d2b375424a31991cf97de19900
Component: engine
2016-01-21 20:49:02 -08:00
b3d838e7cb Merge pull request #19383 from calavera/container_store
Extract container store from the daemon.
Upstream-commit: 9ae51b3e0f01111b743c61d8d0811e7061b490df
Component: engine
2016-01-21 17:20:47 -05:00
793bc88c21 Extract container store from the daemon.
- Generalize in an interface.
- Stop abusing of List for everything.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 3c82fad44112dc73861f325bbecd68b9922b0ad3
Component: engine
2016-01-19 13:21:41 -05:00
5ce70c9580 only close LogDriver after LogCopier is done
this prevents the copier from sending messages in the buffer to the closed
driver. If the copied took longer than the timeout to drain the buffer, this
aborts the copier read loop and return back so we can cleanup resources
properly.

Signed-off-by: Daniel Dao <dqminh@cloudflare.com>
Upstream-commit: 84e14754e1ef3b089442398a31c5c5813fa9a1b6
Component: engine
2016-01-18 17:47:57 +00:00
4a4ab3133f Merge pull request #19339 from cpuguy83/19335_revert_18736
Revert "Break big lock into some tiny locks"
Upstream-commit: 9365b301a821a95e36589c990a36ea4c619b9ba1
Component: engine
2016-01-14 16:53:39 -05:00
082c746378 Merge pull request #19242 from mavenugo/nsalias
Network scoped alias support
Upstream-commit: 73a5393bf3530815a608725fe2546121ccadbfe4
Component: engine
2016-01-14 10:58:51 -08:00
49a1d12f12 Revert "Break big lock into some tiny locks"
This reverts commit 1326f0cba5f933674e23769de1385d3b0841e758.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Upstream-commit: f093e1273d7d030a24045d97a78fec8637f46bf8
Component: engine
2016-01-14 13:38:09 -05:00
8eb1087397 Network scoped alias support
Signed-off-by: Madhu Venugopal <madhu@docker.com>
Upstream-commit: dda513ef651b42fcb9625e651f664554161c0a6a
Component: engine
2016-01-14 08:44:41 -08:00
806650627f Add network ID to container inspect
Fixes issue #19089

Signed-off-by: Wen Cheng Ma <wenchma@cn.ibm.com>
Upstream-commit: 9f676ade0aef66bb66a26171d6bfb27f105fa1df
Component: engine
2016-01-14 22:33:41 +08:00
6c7b14647b Support --link for user-defined networks
This brings in the container-local alias functionality for containers
connected to u ser-defined networks.

Signed-off-by: Madhu Venugopal <madhu@docker.com>
Upstream-commit: e221b8a3d64c13178e156fc3ece5e9894dac1603
Component: engine
2016-01-12 13:38:48 -08:00
5ffd6c31d8 Merge pull request #19121 from WeiZhang555/tty-resize
Check nil Terminal to avoid panic
Upstream-commit: 47074030f6e34fc238ed503e8c8e5ae0ef526e27
Component: engine
2016-01-11 11:29:15 -05:00
ddd50b3705 Merge pull request #18512 from euank/18510-fixOomKilled
Set OOMKilled state on any OOM event
Upstream-commit: 967acd56c175b7c0f3ad4236c664730338a94bb8
Component: engine
2016-01-11 00:09:26 +01:00
7e3ab3dcd7 Merge pull request #19198 from sanimej/vin
Vendoring libnetwork
Upstream-commit: fe3d1f9dd7f2c888ad69034464cba6a35a56018f
Component: engine
2016-01-10 11:46:34 -08:00
7eedab5098 Merge pull request #18736 from WeiZhang555/tiny-lock
Break big lock into some tiny locks for containerStart
Upstream-commit: a082f8083212a50b5a3e40e2d2507b78e0a8e6a8
Component: engine
2016-01-09 00:35:26 +01:00
d8dc8b7d33 Docker changes for libnetwork vendoring..
Signed-off-by: Santhosh Manohar <santhosh@docker.com>
Upstream-commit: 64a6dc355815261ac438b12a262e3cda7c9181df
Component: engine
2016-01-08 14:13:55 -08:00
7467c1af44 Allow user to choose the IP address for the container
Signed-off-by: Alessandro Boch <aboch@docker.com>
Upstream-commit: 2bb3fc1bc522059e9be5bd967b6a5c49917f5d0c
Component: engine
2016-01-08 10:09:16 -08:00
2e84a27cb3 Check nil Terminal to avoid panic
Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
Upstream-commit: 7f0d304f3767d4f33d23480a3ca2f54bb72938b7
Component: engine
2016-01-07 10:07:12 +08:00
4ec2693c9e Modify import paths to point to the new engine-api package.
Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 907407d0b2e5863f0e1b40b93a356bbf03c7b9fb
Component: engine
2016-01-06 19:48:59 -05:00
58e545b6bf Merge pull request #18888 from calavera/event_types
Event all the things!
Upstream-commit: 723be0a3325799fd6b2a6b689af54f5a07edf992
Component: engine
2016-01-04 13:07:33 -08:00
1162375d21 Merge pull request #15666 from vdemeester/3519-configurable-escape
Implement configurable escape key for attach/exec
Upstream-commit: db738dd77f699e93f976441d5fc11ab48a2d6c68
Component: engine
2016-01-04 00:49:07 +01:00
5582f5eb83 Implement configurable detach key
Implement configurable detach keys (for `attach`, exec`, `run` and
`start`) using the client-side configuration

- Adds a `--detach-keys` flag to `attach`, `exec`, `run` and `start`
  commands.
- Adds a new configuration field (in `~/.docker/config.json`) to
  configure the default escape keys for docker client.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 15aa2a663b47b6126a66efefcadb64edfbffb9f5
Component: engine
2016-01-03 23:03:39 +01:00
e54bb2b509 Add volume events.
Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 9d12d093009d3c4bf3bd4ebad3f8327c36d2d584
Component: engine
2015-12-30 17:39:33 -05:00
eee4baf0b5 Fix docker stats show wrong memory limit when do docker update
When a container create with -m 100m and then docker update other
cgroup settings such as --cpu-quota, the memory limit show by
docker stats will become the default value but not the 100m.

Signed-off-by: Lei Jitang <leijitang@huawei.com>
Upstream-commit: 518ed75e1ab5b102fffd7fcbf046c127b44c7be7
Component: engine
2015-12-29 20:33:16 -05:00
c4af30652d Implemet docker update command
It's used for updating properties of one or more containers, we only
support resource configs for now. It can be extended in the future.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Upstream-commit: 8799c4fc0feadede6ae60e77bd7d9dfd7cc72a79
Component: engine
2015-12-28 19:19:26 +08:00
189c56a7c6 Break big lock into some tiny locks
Don't involve code waiting for blocking channel in locked critical
section because it has potential risk of hanging forever.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
Upstream-commit: 1326f0cba5f933674e23769de1385d3b0841e758
Component: engine
2015-12-23 13:23:23 +08:00
027f002cb3 Move Config and HostConfig from runconfig to types/container.
- Make the API client library completely standalone.
- Move windows partition isolation detection to the client, so the
  driver doesn't use external types.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 7ac4232e70fe7cf7318333cd0890db7f95663079
Component: engine
2015-12-22 13:34:30 -05:00
b006691148 Replace usage of pkg/nat with go-connections/nat.
Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 056e7449039af522fa0a1567ef67916eaa0de93e
Component: engine
2015-12-22 13:31:46 -05:00
3d517a11e5 Replace pkg/units with docker/go-units.
Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 4fef42ba206ac90346e6e0fe25bead3f77dc4b0f
Component: engine
2015-12-16 12:26:49 -05:00
014b9947c4 Set OOMKilled state on any OOM event
This restores the behavior that existed prior to #16235 for setting
OOMKilled, while retaining the additional benefits it introduced around
emitting the oom event.

This also adds a test for the most obvious OOM cases which would have
caught this regression.

Fixes #18510

Signed-off-by: Euan <euank@amazon.com>
Upstream-commit: 0b5131444df83eb1e9fe4cfc6bfbf85314e089dc
Component: engine
2015-12-15 19:27:57 +00:00
ff4354d4e6 Merge pull request #18617 from tiborvass/cleanup-builder
Cleanup builder: remove container package dependency
Upstream-commit: 2180dd6cf0258dee45a11ce6bf597448b8157984
Component: engine
2015-12-15 09:59:29 -08:00
2a2006ef18 Merge pull request #17034 from rhvgoyal/volume-propagation
Capability to specify per volume mount propagation mode
Upstream-commit: ce0b1841c82b6972d96654e083f813944e72443f
Component: engine
2015-12-15 12:14:41 -05:00
bf2423fe8a builder: remove container package dependency
Signed-off-by: Tibor Vass <tibor@docker.com>
Upstream-commit: c70f8b3c9c7a6dc6a219354acaa2e650d1403ecf
Component: engine
2015-12-15 17:24:07 +01:00
c0860c6bed Add capability to specify mount propagation per volume
Allow passing mount propagation option shared, slave, or private as volume
property.

For example.
docker run -ti -v /root/mnt-source:/root/mnt-dest:slave fedora bash

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Upstream-commit: a2dc4f79f260247afe55ab7117c9de02a769d883
Component: engine
2015-12-14 10:39:53 -05:00