From 374d1c495a0bd178f40c2048f165072d4ee0b3d9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 11 Apr 2014 18:50:02 -0700 Subject: [PATCH] provisioners/docker: auto-assigned name shouldn't have / [GH-3216] --- CHANGELOG.md | 2 ++ plugins/provisioners/docker/client.rb | 12 ++++++++++-- website/docs/source/v2/provisioning/docker.html.md | 7 +++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59b32f67a66..081bdfcfb13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ BUG FIXES: longer be shown in plaintext in the output. [GH-3203] - guests/linux: SMB mount works with passwords with symbols. [GH-3202] - providers/hyperv: Check for PowerShell features. [GH-3398] + - provisioners/docker: Don't automatically generate container name with + a forward slash. [GH-3216] - provisioners/shell: Empty shell scripts don't cause errors. [GH-3423] - synced\_folders/smb: Only set the chmod properly by default on Windows if it isn't already set. [GH-3394] diff --git a/plugins/provisioners/docker/client.rb b/plugins/provisioners/docker/client.rb index c6afcfdb77e..75457a67990 100644 --- a/plugins/provisioners/docker/client.rb +++ b/plugins/provisioners/docker/client.rb @@ -43,7 +43,8 @@ def run(containers) @machine.ui.info(I18n.t("vagrant.docker_running", name: name)) @machine.communicate.sudo("mkdir -p #{cids_dir}") run_container({ - name: name + name: name, + original_name: name, }.merge(config)) end end @@ -75,9 +76,16 @@ def container_running?(id) end def create_container(config) + name = config[:name] + + # If the name is the automatically assigned name, then + # replace the "/" with "-" because "/" is not a valid + # character for a docker container name. + name = name.gsub("/", "-") if name == config[:original_name] + args = "--cidfile=#{config[:cidfile]} " args << "-d " if config[:daemonize] - args << "--name #{config[:name]} " if config[:name] && config[:auto_assign_name] + args << "--name #{name} " if name && config[:auto_assign_name] args << config[:args] if config[:args] @machine.communicate.sudo %[ rm -f #{config[:cidfile]} diff --git a/website/docs/source/v2/provisioning/docker.html.md b/website/docs/source/v2/provisioning/docker.html.md index 71b5acf6590..f940db4360b 100644 --- a/website/docs/source/v2/provisioning/docker.html.md +++ b/website/docs/source/v2/provisioning/docker.html.md @@ -137,8 +137,11 @@ In addition to the name, the `run` method accepts a set of options, all optional * `args` (string) - Extra arguments for [`docker run`](http://docs.docker.io/en/latest/commandline/cli/#run) on the command line. These are raw arguments that are passed directly to Docker. -* `auto_assign_name` (boolean) - If true, the `-name` of the container will - be set to the first argument of the run. By default this is true. +* `auto_assign_name` (boolean) - If true, the `--name` of the container will + be set to the first argument of the run. By default this is true. If the + name set contains a "/" (because of the image name), it will be replaced + with "-". Therefore, if you do `d.run "foo/bar"`, then the name of the + container will be "foo-bar". * `daemonize` (boolean) - If true, the "-d" flag is given to `docker run` to daemonize the containers. By default this is true.