Skip to content

Instantly share code, notes, and snippets.

@dariubs
Last active December 10, 2020 08:31
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dariubs/793287b0e6d67238aa21f17d03f9dd3e to your computer and use it in GitHub Desktop.
Save dariubs/793287b0e6d67238aa21f17d03f9dd3e to your computer and use it in GitHub Desktop.
influxdb cheatsheet

Influxdb cheatsheet

Install with docker

Pull the latest version of influxdb official image :

docker pull influxdb

Or pull specific version of influxdb official image :

docker pull influxdb:<version>

Create a directory for influxdb data volume and change directory to it:

mkdir ~/influxtest && cd ~/influxtest

Run influxdb container:

docker run --name influxtest -d -p 8086:8086 \
      -v $PWD:/var/lib/influxdb \
      influxdb

For run with custom config file :

First generate default configuration file :

docker run --rm influxdb influxd config > influxdb.conf

If you want to enable user authentication on http, enable auth-enabled option in config file:

[http]
  ...
  auth-enabled = true
  ...

Then create an admin user :

docker run --rm --link=influxtest -it influxdb influx -host influxtest -execute "CREATE USER myname WITH PASSWORD '123456' WITH ALL PRIVILEGES"

Then run the container:

docker run --name influxtest -d -p 8086:8086 \
      -v $PWD:/var/lib/influxdb \
      -v $PWD/influxdb.conf:/etc/influxdb/influxdb.conf:ro \
      influxdb -config /etc/influxdb/influxdb.conf

Influxdb CLI

Run influxdb cli client in another container linked to influxtest container:

docker run --rm --link=influxtest -it influxdb influx -host influxtest

Query In CLI

If you enable user authentication, authenticate your user first:

auth

Create a new database:

CREATE DATABASE <dbname>

Show list of databases:

SHOW DATABASES

Use a database:

USE <dbname>
@majerus1223
Copy link

majerus1223 commented Jan 18, 2018

Then run the container throws error

`Error response from daemon:

Conflict. The container name "/influxtest" is already in use by container "23706448f8f9c14bb95321faa224f6de72a3e8f21bde031c257d163707f8d5ea". You have to remove (or rename) that container to be able to reuse that name`

@dariubs
Copy link
Author

dariubs commented Jun 8, 2018

@majerus1223 You can use another name instead of influxtest

@monteirobrena
Copy link

Then run the container throws error

`Error response from daemon:

Conflict. The container name "/influxtest" is already in use by container "23706448f8f9c14bb95321faa224f6de72a3e8f21bde031c257d163707f8d5ea". You have to remove (or rename) that container to be able to reuse that name`

Run the ps to get ID:
$ docker ps -a | grep influxtest

The return will be something like:
8ba1158110db quay.io/influxdb/influxdb:v2.0.2 "/entrypoint.sh infl…" 3 minutes ago Exited (0) 2 minutes ago influxtest

Remove the container passing the found ID:
$ docker rm 8ba1158110db
8ba1158110db

Run the ps again to check if the container was removed:
$ docker ps -a | grep influxtest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment