Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid auto-generated container name using Docker provider and a folder that starts with an underscore #13484

Open
Jaymon opened this issue Aug 3, 2024 · 0 comments

Comments

@Jaymon
Copy link

Jaymon commented Aug 3, 2024

Running vagrant up in a folder that begins with an underscore (eg, _foo) using the docker provider that does not explicitely set the name attribute results in an Invalid container name error.

Debug output

It's easy to see the problem so I don't think the debug output is needed since the error lies in the auto container name code of the docker provider.

Expected behavior

It was expected for vagrant up to succeed and bring up the docker container with an auto-generated name.

Actual behavior

A Docker command executed by Vagrant didn't complete successfully!
The command run along with the output from the command is shown
below.

Command: ["docker", "run", "--name", "_foo_default_1722722989", "-d", "-v", ".../_foo:/vagrant", "57ed1512823d6c273d82fe84bf974a3f7b833c2065787e655ae9746719f99866", {:notify=>[:stdout, :stderr]}]

Stderr: docker: Error response from daemon: Invalid container name (_foo_default_1722722989), only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed.
See 'docker run --help'.

Reproduction information

Vagrant version

$ vagrant -v
Vagrant 2.4.1

Host operating system

macOs Sonoma 14.4.1

Guest operating system

Ubuntu 20.04

Steps to reproduce

  1. Create a folder that starts with an underscore (eg _foo)
  2. Create a minimal Dockerfile in that directory (eg _foo/Dockerfile:
    FROM ubuntu:20.04
    CMD ["sleep", "infinity"]
    
  3. Create a minimal Vagrantfile in that directory (eg _foo/Vagrantfile) (see the Vagrantfile section for the contents)

You can fix the error and successfully bring up the docker container by adding to the Vagrantfile's docker config block:

d.name = "foo"

Which bypasses the auto name generating code.

Vagrantfile

Vagrant.configure("2") do |config|

  config.vm.provider :docker do |d|
    d.build_dir = "."
    d.remains_running = true
  end

end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant