I want to create a database at the launch of the InfluxDB container in docker. I went through this previously asked question Launching a InfluxDB container in docker with a default database name which is about 3 years old.
By referring the solution of that question, I used the following command to run the image.
docker run -d --name influxdb -p 8086:8086 \
-e INFLUXDB_DB=databasenew \
-e INFLUXDB_ADMIN_USER=admin \
-e INFLUXDB_ADMIN_PASSWORD=admin \
-v /var/lib/influxdb:/var/lib/influxdb \
influxdb:1.8
But, it doesn't create a new database named as "databasenew".
In the above docker command, I use -v /var/lib/influxdb:/var/lib/influxdb to mount my local influxdb data to the container.
When I use -v influxdb:/var/lib/influxdb in the docker command, it creates a database named as "databasenew". But the database location is not my local influxdb location.
So how to create the database when launching the influxdb container with host location (/var/lib/influxdb) mounted as the volume.
Update
After checking the logs, I realized that, if the mounted volume already has a database, docker avoid to create a new database even though the database names are different. If the volume is fresh and no databases exist, then docker engine creates the new database mentioned in INFLUXDB_DB
There can be situations which I want to create a new database in the existing volume. How can I achieve that ?