Skip to content

Commit

Permalink
provisioners/docker: auto-assigned name shouldn't have / [GH-3216]
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Apr 12, 2014
1 parent c4c8dbc commit 374d1c4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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]
Expand Down
12 changes: 10 additions & 2 deletions plugins/provisioners/docker/client.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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]}
Expand Down
7 changes: 5 additions & 2 deletions website/docs/source/v2/provisioning/docker.html.md
Expand Up @@ -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.
Expand Down

0 comments on commit 374d1c4

Please sign in to comment.