Browse code

Early deprecation warning for 'docker commit --run'

Warn users of the planned deprecation of 'docker commit --run', and hide
it from the docs and usage message. The option continues to work.

Note that an alternative to 'commit --run' is being implemented but is
not yet available. We are printing the warning anyway because on
the basis that it never hurts to give more advance warning.

The 'commit --run' flag is a leftover from the very early days of Docker,
and has several problems:

1) It is very user unfriendly. You have to pass a literal json dict
which is poorly documented and changes regularly (see PortSpecs vs
ExposedPorts). The merge behavior is not clear and also changes
regularly. it's not possible to unset a value.

2) It overlaps with the Dockerfile syntax. There are 2 ways to set
a default command, expose a port or change an env variable. Some
things can be done in a Dockerfile but not in --run. Some things
can be done in --run but not in a Dockerfile. It would be better
to push a single syntax, allow using it both in a file and via
the command line, and make improvements in a single place.

3) It exposes data structures which should not be publicly exposed.
There are several planned improvements to Docker which require moving
around the content and schema of the various Config, Image and Container
structures. The less of those we expose in public interfaces, the easier
it is to move things around without a reverse compatibility nightmare.

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)

Solomon Hykes authored on 2014/04/09 01:49:48
Showing 3 changed files
... ...
@@ -1433,7 +1433,8 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
1433 1433
 	cmd := cli.Subcmd("commit", "[OPTIONS] CONTAINER [REPOSITORY[:TAG]]", "Create a new image from a container's changes")
1434 1434
 	flComment := cmd.String([]string{"m", "-message"}, "", "Commit message")
1435 1435
 	flAuthor := cmd.String([]string{"a", "#author", "-author"}, "", "Author (eg. \"John Hannibal Smith <hannibal@a-team.com>\"")
1436
-	flConfig := cmd.String([]string{"#run", "-run"}, "", "Config automatically applied when the image is run. "+`(ex: --run='{"Cmd": ["cat", "/world"], "PortSpecs": ["22"]}')`)
1436
+	// FIXME: --run is deprecated, it will be replaced with inline Dockerfile commands.
1437
+	flConfig := cmd.String([]string{"#run", "#-run"}, "", "this option is deprecated and will be removed in a future version in favor of inline Dockerfile-compatible commands")
1437 1438
 	if err := cmd.Parse(args); err != nil {
1438 1439
 		return nil
1439 1440
 	}
... ...
@@ -1471,6 +1472,7 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
1471 1471
 		env    engine.Env
1472 1472
 	)
1473 1473
 	if *flConfig != "" {
1474
+		fmt.Fprintf(cli.err, "WARNING: 'commit --run' is deprecated and will be removed in a future version, in favor of inline Dockerfile-compatible commands.\n")
1474 1475
 		config = &runconfig.Config{}
1475 1476
 		if err := json.Unmarshal([]byte(*flConfig), config); err != nil {
1476 1477
 			return err
... ...
@@ -188,9 +188,7 @@ omit the executable, in which case you must specify an ENTRYPOINT as
188 188
 well.
189 189
 
190 190
 When used in the shell or exec formats, the ``CMD`` instruction sets
191
-the command to be executed when running the image.  This is
192
-functionally equivalent to running ``docker commit --run '{"Cmd":
193
-<command>}'`` outside the builder.
191
+the command to be executed when running the image.
194 192
 
195 193
 If you use the *shell* form of the CMD, then the ``<command>`` will
196 194
 execute in ``/bin/sh -c``:
... ...
@@ -230,10 +228,10 @@ override the default specified in CMD.
230 230
 
231 231
     ``EXPOSE <port> [<port>...]``
232 232
 
233
-The ``EXPOSE`` instruction exposes ports for use within links. This is
234
-functionally equivalent to running ``docker commit --run '{"PortSpecs":
235
-["<port>", "<port2>"]}'`` outside the builder. Refer to
236
-:ref:`port_redirection` for detailed information.
233
+The ``EXPOSE`` instructions informs Docker that the container will listen
234
+on the specified network ports at runtime. Docker uses this information
235
+to interconnect containers using links (see :ref:`links <working_with_links_names>`),
236
+and to setup port redirection on the host system (see :ref:`port_redirection`).
237 237
 
238 238
 .. _dockerfile_env:
239 239
 
... ...
@@ -316,8 +316,6 @@ by using the ``git://`` schema.
316 316
 
317 317
       -m, --message="": Commit message
318 318
       -a, --author="": Author (eg. "John Hannibal Smith <hannibal@a-team.com>"
319
-      --run="": Configuration changes to be applied when the image is launched with `docker run`.
320
-               (ex: --run='{"Cmd": ["cat", "/world"], "PortSpecs": ["22"]}')
321 319
 
322 320
 .. _cli_commit_examples:
323 321
 
... ...
@@ -336,96 +334,6 @@ Commit an existing container
336 336
 	REPOSITORY                        TAG                 ID                  CREATED             VIRTUAL SIZE
337 337
 	SvenDowideit/testimage            version3            f5283438590d        16 seconds ago      335.7 MB
338 338
 
339
-Change the command that a container runs
340
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
341
-
342
-Sometimes you have an application container running just a service and you need
343
-to make a quick change and then change it back.
344
-
345
-In this example, we run a container with ``ls`` and then change the image to
346
-run ``ls /etc``.
347
-
348
-.. code-block:: bash
349
-
350
-        $ docker run -t --name test ubuntu ls
351
-        bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  selinux  srv  sys  tmp  usr  var
352
-        $ docker commit --run='{"Cmd": ["ls","/etc"]}' test test2
353
-        933d16de9e70005304c1717b5c6f2f39d6fd50752834c6f34a155c70790011eb
354
-        $ docker run -t test2
355
-        adduser.conf            gshadow          login.defs           rc0.d
356
-        alternatives            gshadow-         logrotate.d          rc1.d
357
-        apt                     host.conf        lsb-base             rc2.d
358
-        ...
359
-
360
-Merged configs example
361
-......................
362
-
363
-Say you have a Dockerfile like so:
364
-
365
-.. code-block:: bash
366
-
367
-        ENV MYVAR foobar
368
-        RUN apt-get install openssh
369
-        EXPOSE 22
370
-        CMD ["/usr/sbin/sshd -D"]
371
-        ...
372
-
373
-If you run that, make some changes, and then commit, Docker will merge the environment variable and exposed port configuration settings with any that you specify in the --run= option. This is a change from Docker 0.8.0 and prior where no attempt was made to preserve any existing configuration on commit.
374
-
375
-.. code-block:: bash
376
-
377
-        $ docker build -t me/foo .
378
-        $ docker run -t -i me/foo /bin/bash
379
-        foo-container$ [make changes in the container]
380
-        foo-container$ exit
381
-        $ docker commit --run='{"Cmd": ["ls"]}' [container-id] me/bar
382
-        ...
383
-
384
-The me/bar image will now have port 22 exposed, MYVAR env var set to 'foobar', and its default command will be ["ls"].
385
-
386
-Note that this is currently a shallow merge. So, for example, if you had specified a new port spec in the --run= config above, that would have clobbered the 'EXPOSE 22' setting from the parent container.
387
-
388
-Full --run example
389
-..................
390
-
391
-The ``--run`` JSON hash changes the ``Config`` section when running ``docker inspect CONTAINERID``
392
-or ``config`` when running ``docker inspect IMAGEID``. Existing configuration key-values that are
393
-not overridden in the JSON hash will be merged in.
394
-
395
-(Multiline is okay within a single quote ``'``)
396
-
397
-.. code-block:: bash
398
-
399
-  $ sudo docker commit --run='
400
-  {
401
-      "Entrypoint" : null,
402
-      "Privileged" : false,
403
-      "User" : "",
404
-      "VolumesFrom" : "",
405
-      "Cmd" : ["cat", "-e", "/etc/resolv.conf"],
406
-      "Dns" : ["8.8.8.8", "8.8.4.4"],
407
-      "DnsSearch" : ["example.com"],
408
-      "MemorySwap" : 0,
409
-      "AttachStdin" : false,
410
-      "AttachStderr" : false,
411
-      "CpuShares" : 0,
412
-      "OpenStdin" : false,
413
-      "Volumes" : null,
414
-      "Hostname" : "122612f45831",
415
-      "PortSpecs" : ["22", "80", "443"],
416
-      "Image" : "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
417
-      "Tty" : false,
418
-      "Env" : [
419
-         "HOME=/",
420
-         "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
421
-      ],
422
-      "StdinOnce" : false,
423
-      "Domainname" : "",
424
-      "WorkingDir" : "/",
425
-      "NetworkDisabled" : false,
426
-      "Memory" : 0,
427
-      "AttachStdout" : false
428
-  }' $CONTAINER_ID
429 339
 
430 340
 .. _cli_cp:
431 341