docker-mysql-scripts icon indicating copy to clipboard operation
docker-mysql-scripts copied to clipboard

Naming data containers

Open psychemedia opened this issue 11 years ago • 3 comments

At the moment, data volume containers are named as a derivative of the original container name: containerName.upper() + '_DATA'

Would it be useful to optionally allow the creation and/or use of specifically named data volume containers?

I can imagine four cases:

  • current default: when running dmysql-server to create a sever named foo, create a data volume container named foo_DATA
  • using a pre-existing container (1): if we have dmysql-server --volumes-from to create a container foo, where --volumes-from is a flag, then link to foo_DATA;
  • using a pre-existing container (2): what about if we don't want to automatically generate the named of the linked data volume container? Do we need another parameter, eg --data-volume NAME that runs as --volumes-from NAME as part of runContainer()? In this case, should we require --volumes-from --data-volume NAME? What should happen if --volumes-from flag is not set (that is, only --data-volume NAME is supplied)? Or should --data-volume NAME force the setting of --volumes-from as true?
  • creating a custom named data container: again using eg --data-volume NAME, rather than running createVolume(containerName.upper() + '_DATA') we run createVolume(NAME)?

If we take this approach, is --data-volume NAME sensible? Or should it be called something else? --data-volume-name NAME ?

psychemedia avatar Jan 14 '15 19:01 psychemedia

I've been thinking about this for like 10 minutes because as you say, there are multiple scenarios.

  1. --volumes-from is not used so no problem here.
  2. --volumes-from is used and a new data-only container is created with the value FOO_DATA
  3. It should be possible to enter the name of the data-only container.
  4. It should be possible to link a pre-existing data-only container.

So I do agree, but the question is how?

As you mention, --volumes-from with no options could default to FOO_DATA. With an option, it could use the argument as the name for the container, and if the container is already created, it could just link it.

Right now, I don't know how to check if the container exists and then decide if is going to be created or just linked it, probably it will be necessary to query the Docker API to do this.

luiselizondo avatar Jan 14 '15 22:01 luiselizondo

Okay, so that's yet another binary question - does a container we are trying to link to exist or not?

psychemedia avatar Jan 15 '15 00:01 psychemedia

I've popped a revision of dmysql-server at https://github.com/psychemedia/docker-mysql-scripts but haven't submitted a pull request because I haven't had time to properly test it yet (and possibly won't have time now for a day or two). The updated README explains the usage.

I also started mulling over a script dmysql-server-rm to remove a server and any associated volumes or data volume containers so that stuff didn't start getting left all over the place.

psychemedia avatar Jan 15 '15 12:01 psychemedia