Skip to content

Commit 168f8ab

Browse files
author
Solomon Hykes
committed
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 <[email protected]> (github: shykes)
1 parent 8cfbc44 commit 168f8ab

3 files changed

Lines changed: 8 additions & 100 deletions

File tree

api/client/commands.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,8 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
14331433
cmd := cli.Subcmd("commit", "[OPTIONS] CONTAINER [REPOSITORY[:TAG]]", "Create a new image from a container's changes")
14341434
flComment := cmd.String([]string{"m", "-message"}, "", "Commit message")
14351435
flAuthor := cmd.String([]string{"a", "#author", "-author"}, "", "Author (eg. \"John Hannibal Smith <[email protected]>\"")
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")
14371438
if err := cmd.Parse(args); err != nil {
14381439
return nil
14391440
}
@@ -1471,6 +1472,7 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
14711472
env engine.Env
14721473
)
14731474
if *flConfig != "" {
1475+
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")
14741476
config = &runconfig.Config{}
14751477
if err := json.Unmarshal([]byte(*flConfig), config); err != nil {
14761478
return err

docs/sources/reference/builder.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ omit the executable, in which case you must specify an ENTRYPOINT as
188188
well.
189189

190190
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.
194192

195193
If you use the *shell* form of the CMD, then the ``<command>`` will
196194
execute in ``/bin/sh -c``:
@@ -230,10 +228,10 @@ override the default specified in CMD.
230228

231229
``EXPOSE <port> [<port>...]``
232230

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.
231+
The ``EXPOSE`` instructions informs Docker that the container will listen
232+
on the specified network ports at runtime. Docker uses this information
233+
to interconnect containers using links (see :ref:`links <working_with_links_names>`),
234+
and to setup port redirection on the host system (see :ref:`port_redirection`).
237235

238236
.. _dockerfile_env:
239237

docs/sources/reference/commandline/cli.rst

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ by using the ``git://`` schema.
316316

317317
-m, --message="": Commit message
318318
-a, --author="": Author (eg. "John Hannibal Smith <[email protected]>"
319-
--run="": Configuration changes to be applied when the image is launched with `docker run`.
320-
(ex: --run='{"Cmd": ["cat", "/world"], "PortSpecs": ["22"]}')
321319

322320
.. _cli_commit_examples:
323321

@@ -336,96 +334,6 @@ Commit an existing container
336334
REPOSITORY TAG ID CREATED VIRTUAL SIZE
337335
SvenDowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB
338336
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
429337
430338
.. _cli_cp:
431339

0 commit comments

Comments
 (0)