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 ?
Related
please bear in mind this is my first time posting here I might not know all the rules and stuff.
so I have just started working with dockers and images. I created a small .Net app and I used MsSQLServer docker image in my app. The app gets connected with the server and I am able to create database using CodeFirst approach (add-migration and update database works fine).
i am running my SQL container with -rm mode. Although it has a volume mounted to it but i have to create database every time i rerun the container.
I read that if we want our data not to get lost when we delete the container we have to mount volumes to our container. i had done the same thing using MongoDb docker image and it worked fine. my data is still present even when i stop and rerun my MongoContainer. but my MSSQL is unable to retain data.
here is the command i m using to run my docker image ( i know about docker-compose but i am avoiding using it for now)
docker run -d --rm --name mssqlserver -p 1433:1433 -e "ACCEPT_EULA=Y" -e MSSQL_SA_PASSWORD=********** -v sqlData:/data/db mcr.microsoft.com/mssql/server
Note: this says it will not delete named volume with --rm
https://docs.docker.com/engine/reference/run/#clean-up---rm
The path you mount the volume on is a Linux path, so you need to use forward slashes rather than back-slashes, like this
docker run -d --rm --name mssqlserver -p 1433:1433 -e "ACCEPT_EULA=Y" -e MSSQL_SA_PASSWORD=********** -v sqlData:/var/opt/mssql mcr.microsoft.com/mssql/server
I'm running a docker container of a db/2 luw image (custom image of a DB2ExpressC on RHEL). The container exposes the service to port 50000 and is available from the "outside". The user is db2inst1 and seems to be a standard username for the database.
I start the container with the following command:
docker run --rm -itd -e DB2INST1_PASSWORD=kvl -e DBNAME=BLA -p 50000:50000 -v db2luw:/home/db2inst1 db2:v11.1-7
When i look into the container there is a home-directory of the db2inst1 user wherein the db-instance places its data. I thought if i create a volume with the home-directory as mountpoint, it would cause my data to be persistet in it after a restart of the container.
Has anyone an idea what the problem could be? I cant find a wiki or useful documentation.
The solution was to create the volume with the correct target (mount-point). The db2-image uses
/home/db2inst1/data
as its data-directory.
I downloaded 2 versions of neo4j on Ubuntu 18.04 which are "neo4j-community-3.5.12" and "neo4j-community-3.5.8"
I run 3.5.8 with default settings I can see it from the web. http://localhost:7474/
For 3.5.12 I changed conf/neo4j.conf file and set some other port numbers for not to conflict with the default ones.
3.5.8 version runs fine on :7474. When I start 3.5.12, the logs says it is running but when I check from browser it is not running. I tried 2 different port settings, none worked. Below is the log file.
Why it is not running?
I see that many people recommended using docker. I also tried that.
I set up docker a container with command
sudo docker run --name db1 -p7474:7474 -p7687:7687 -d -v /db1/data:/data -v /db1/logs:/logs -v /db1/conf:/conf --env NEO4J_AUTH=none neo4j
here I have an existing /d1/data/databases/graph.db folder. When I go to localhost:7474 it is fine it shows me the existing database.
I set up another docker container with command
sudo docker run --name db2 -p3001:7474 -p3002:7473 -p3003:7687 -d -v /db2/data:/data -v /db2/logs:/logs -v /db2/conf:/conf --env NEO4J_AUTH=none neo4j
here I expect to see an EMPTY database but I see the already existing database again. When I go to the data folder inside db2. I see that it created some files here. WHY do I see the same database?
Also note that when I go to see the databases, headers of the web pages showing they are using the same bolt port?
can I copy the neo4j image and use different images to generate containers? Does that help?
I recognized that multiple databases are running and active but somehow I'm not able to reach the second one through a browser.
Considering the docker commands-
cmd1: sudo docker run --name db1 -p7474:7474 -p7687:7687 -d -v /db1/data:/data -v /db1/logs:/logs -v /db1/conf:/conf --env NEO4J_AUTH=none neo4j
cmd2: sudo docker run --name db2 -p3001:7474 -p3002:7473 -p3003:7687 -d -v /db2/data:/data -v /db2/logs:/logs -v /db2/conf:/conf --env NEO4J_AUTH=none neo4j
The container ports are defaults exposed as the same host port for db1 instance. Whereas for db2 instance series 3xxx has been used.
To browse the UI provided by neo4j, you can use either 7474 or 3001 port which is mapped to 7474 container port.
Neo4j browser uses defaults (from neo4j.conf) to connect to neo4j server. The default settings are as
bolt://<machineip>:7687, where db1 instance has already exposed the container port to 7687 host port.
A running instance is found on 7687 port which initiates a WebSocket connection for db1 and db2.
How to connect to an appropriate instance?
Use: :server disconnect and :server connect with the appropriate bolt://<machineip>:port connection string
Map db1 instance bolt container port to different host port (i.e. other than 7687)
As no defaults will be available
(Preferred), set the same hostport:containerport combination e.g.
cmd2: sudo docker run --name db2 -p3001:7474 -p3002:7473 -p3003:3003-d -v /db2/data:/data -v /db2/logs:/logs -v /db2/conf:/conf --env NEO4J_AUTH=none neo4j
in this case, a Volume has to be mapped to provide neo4j.conf with updated values as dbms.connector.bolt.listen_address=:3003
In case anybody still needs it: Here is how to run two neo4j databases neo4j_01 and neo4j_02 in two different docker containers, saving the data in different directories and accessing them on different ports.
docker container 1: neo4j_01
docker run \
--name neo4j_01 \
-p1474:7474 -p1687:7687 \
-d \
-v $HOME/neo4j_01/neo4j/data:/data \
-v $HOME/neo4j_01/neo4j/logs:/logs \
-v $HOME/neo4j_01/neo4j/import:/var/lib/neo4j/import \
-v $HOME/neo4j_01/neo4j/plugins:/plugins \
--env NEO4J_AUTH=username/enterpasswordhere \
neo4j:latest
docker container 2: neo4j_02
docker run \
--name neo4j_02 \
-p2474:7474 -p2687:7687 \
-d \
-v $HOME/neo4j_02/neo4j/data:/data \
-v $HOME/neo4j_02/neo4j/logs:/logs \
-v $HOME/neo4j_02/neo4j/import:/var/lib/neo4j/import \
-v $HOME/neo4j_02/neo4j/plugins:/plugins \
--env NEO4J_AUTH=username/enterpasswordhere \
neo4j:latest
After executing the code above e.g. neo4j_01 can be reached on port 1474 (when logging in you need to change the bolt port to 1687 in the first line and then enter username and password in second and third line)
You can stop a container with docker kill neo4j_01 and restart it with docker start neo4j_01. Data will still be there. It is saved in $HOME/neo4j_01/neo4j/data.
Doing it like this, I did not encounter any problems with ports/ accessing the wrong database etc.
After a lot of effort, my solution is not to use docker.
Go and download a community server from here. https://neo4j.com/download-center/#community. It will give you a compressed file. Extract it. You will have a folder named like neo4j-community-3.5.14. Make a copy of THAT FOLDER. For each server instance, make a copy.
Inside the folder, there is a conf folder which has a file named neo4j.conf. Open that file. By changing some settings inside this folder, you can run many neo4j servers. Change the below settings
To accept non-local connections, uncomment this line:
dbms.connectors.default_listen_address=0.0.0.0
change some port numbers so that they won't intersect with already used ones
dbms.connector.bolt.listen_address=:3003
dbms.connector.https.listen_address=:3002
dbms.connector.http.listen_address=:3001
In my ubuntu 18.04, installed couch db using this repo. In order to data persistance, i have created docker volume using the command docker volume create --name couchdbvolume.
I used docker run -p 5984:5984 -d couchdb -v couchdbvolume:/opt/couchdb/data --name some-couchdb command to create new docker process. Instead of using existing volume, every time docker creates new volume. So i loss data in every restart.
As per this question , un-named volumes are created if the docker file doesn't have name in volume keyword. I think because of this line the volume doesn't have name. so it creates un-named volume.
Instead of multiple docker volume,
I expect, only one docker volume(i have only one couchdb docker image)
According to the documentation, options should precede the image name.
$ docker run [OPTIONS] IMAGE[:TAG|#DIGEST] [COMMAND] [ARG...]
please try the following:
docker run -p 5984:5984 -d -v couchdbvolume:/opt/couchdb/data --name some-couchdb couchdb
I followed the standard Odoo container instructions on Docker to start the required postgres and odoo servers, and tried to pass host directories as persistent data storage for both as indicated in those instructions:
sudo mkdir /tmp/postgres /tmp/odoo
sudo docker run -d -v /tmp/postgres:/var/lib/postgresql/data/pgdata -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --name db postgres:10
sudo docker run -v /tmp/odoo:/var/lib/odoo -p 8069:8069 --name odoo --link db:db -t odoo
The Odoo container shows messages that it starts up fine, but when I point my web browser at http://localhost:8069 I get no response from the server. By contrast, if I omit the -v argument from the Odoo docker run command, my web browser connects to the Odoo server fine, and everything works great.
I searched and see other people also struggling with getting the details of persistent data volumes working, e.g. Odoo development on Docker, Encountered errors while bringing up the project
This seems like a significant gap in Docker's standard use-case that users need better info on how to debug:
How to debug why the host volume mounting doesn't work for the odoo container, whereas it clearly does work for the postgres container? I'm not getting any insight from the log messages.
In particular, how to debug whether the container requires the host data volume to be pre-configured in some specific way, in order to work? For example, the fact that I can get the container to work without the -v option seems like it ought to be helpful, but also rather opaque. How can I use that success to inspect what those requirements actually are?
Docker is supposed to help you get a useful service running without needing to know the guts of its internals, e.g. how to set up its internal data directory. Mounting a persistent data volume from the host is a key part of that, e.g. so that users can snapshot, backup and restore their data using tools they already know.
I figured out some good debugging methods that both solved this problem and seem generally useful for figuring out Docker persistent data volume issues.
Test 1: can the container work with an empty Docker volume?
This is a really easy test: just create a new Docker volume and pass that in your -v argument (instead of a host directory absolute path):
sudo docker volume create hello
sudo docker run -v hello:/var/lib/odoo -p 8069:8069 --name odoo --link db:db -t odoo
The odoo container immediately worked successfully this way (i.e. my web browswer was able to connect to the Odoo server). This showed that it could work fine with an (initially) empty data directory. The obvious question then is why it didn't work with an empty host-directory volume. I had read that Docker containers can be persnickety about UID/GID ownership, so my next question was how do I figure out what it expects.
Test 2: inspect the running container's file system
I used docker exec to get an interactive bash shell in the running container:
sudo docker exec -ti odoo bash
Inside this shell I then looked at the data directory ownership, to get numeric UID and GID values:
ls -dn /var/lib/odoo
This showed me the UID/GID values were 101:101. (You can exit from this shell by just typing Control-D)
Test 3: re-run container with matching host-directory UID:GID
I then changed the ownership of my host directory to 101:101 and re-ran the odoo container with my host-directory mount:
sudo chown 101:101 /tmp/odoo
sudo docker stop odoo
sudo docker rm odoo
sudo docker run -v /tmp/odoo:/var/lib/odoo -p 8069:8069 --name odoo --link db:db -t odoo
Success! Finally the odoo container worked properly with a host-directory mount. While it's annoying the Odoo docker docs don't mention anything about this, it's easy to debug if you know how to use these basic tests.