provisioners/docker: auto-assigned name shouldn't have / [GH-3216]

This commit is contained in:
Mitchell Hashimoto 2014-04-11 18:50:02 -07:00
parent c4c8dbc888
commit 374d1c495a
3 changed files with 17 additions and 4 deletions

View File

@ -33,6 +33,8 @@ BUG FIXES:
longer be shown in plaintext in the output. [GH-3203] longer be shown in plaintext in the output. [GH-3203]
- guests/linux: SMB mount works with passwords with symbols. [GH-3202] - guests/linux: SMB mount works with passwords with symbols. [GH-3202]
- providers/hyperv: Check for PowerShell features. [GH-3398] - 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] - provisioners/shell: Empty shell scripts don't cause errors. [GH-3423]
- synced\_folders/smb: Only set the chmod properly by default on Windows - synced\_folders/smb: Only set the chmod properly by default on Windows
if it isn't already set. [GH-3394] if it isn't already set. [GH-3394]

View File

@ -43,7 +43,8 @@ module VagrantPlugins
@machine.ui.info(I18n.t("vagrant.docker_running", name: name)) @machine.ui.info(I18n.t("vagrant.docker_running", name: name))
@machine.communicate.sudo("mkdir -p #{cids_dir}") @machine.communicate.sudo("mkdir -p #{cids_dir}")
run_container({ run_container({
name: name name: name,
original_name: name,
}.merge(config)) }.merge(config))
end end
end end
@ -75,9 +76,16 @@ module VagrantPlugins
end end
def create_container(config) 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 = "--cidfile=#{config[:cidfile]} "
args << "-d " if config[:daemonize] 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] args << config[:args] if config[:args]
@machine.communicate.sudo %[ @machine.communicate.sudo %[
rm -f #{config[:cidfile]} rm -f #{config[:cidfile]}

View File

@ -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) * `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. 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 * `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. 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` (boolean) - If true, the "-d" flag is given to `docker run` to
daemonize the containers. By default this is true. daemonize the containers. By default this is true.