Search code examples
dockervagrant

Error response from daemon: Invalid container name (tomcat:8.0), only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed


I'm trying to run a docker container by Vagrant Docker provision:

d.run "tomcat:8.0", args: "-it -d -p 8888:8888 --name tomcat8"

Vagrant pulls the image fine, but when it comes to running the container I get a:

Error response from daemon: Invalid container name (tomcat:8.0), only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed

I would like to keep the :8.0 so that I'm sure I run the right image version.


Solution

  • Well it turned out that Vagrant by default uses the image name as container name even if I used the --name arg.

    In my case that was unfortunate since I was pulling from the official Tomcat repository at Dockerhub and hence could not change the image name.

    What I found was that Vagrant has an extra setting called auto_assign_name which must be set to false in order to use the --name arg.

    So a working Vagrant line would be:

    d.run "tomcat:8.0", args: "-it -p 8080:8080 --name tomcat8", auto_assign_name: false