|
| 1 | +:description: Running Neo4j in a Docker container using Docker Compose |
| 2 | +[[docker-compose-neo4j-standalone]] |
| 3 | += Deploy a Neo4j standalone server using Docker Compose |
| 4 | + |
| 5 | +You can deploy a Neo4j standalone server using Docker Compose by defining the container configuration in a _docker-compose.yml_ file and authenticating with basic authentication or Docker secrets. |
| 6 | + |
| 7 | +[[docker-compose-basic-authentication]] |
| 8 | +== Deploy a Neo4j server using basic authentication mechanism |
| 9 | + |
| 10 | +Before you start, verify that you have installed Docker Compose. |
| 11 | +For more information, see the https://docs.docker.com/compose/install/[Install Docker Compose official documentation]. |
| 12 | + |
| 13 | +. Create a project folder where you will store your _docker-compose.yml_ file and run your Neo4j server. |
| 14 | +. Prepare your _docker-compose.yml_ file using the following example. |
| 15 | +For more information, see the Docker Compose official documentation on https://docs.docker.com/compose/compose-file/#service-configuration-reference[Docker Compose specification]. |
| 16 | ++ |
| 17 | +.Example of a _docker-compose.yml_ file |
| 18 | +[source,yaml,subs="attributes+,+macros"] |
| 19 | +---- |
| 20 | +services: |
| 21 | + neo4j: |
| 22 | + image: neo4j:latest |
| 23 | + volumes: # <1> |
| 24 | + - /$HOME/neo4j/logs:/logs |
| 25 | + - /$HOME/neo4j/config:/config |
| 26 | + - /$HOME/neo4j/data:/data |
| 27 | + - /$HOME/neo4j/plugins:/plugins |
| 28 | + environment: |
| 29 | + - NEO4J_AUTH=neo4j/your_password # <2> |
| 30 | + ports: |
| 31 | + - "7474:7474" |
| 32 | + - "7687:7687" |
| 33 | + restart: always |
| 34 | +---- |
| 35 | +<1> Mount the _/$HOME/neo4j/<..>:_ directories to local directories on your host machine to store logs, configuration, data, and plugins. |
| 36 | +For more information about mounting volumes, see xref:docker/mounting-volumes.adoc[]. |
| 37 | +<2> Set the `neo4j` username and password. |
| 38 | + |
| 39 | +. Deploy your Neo4j server by running `docker-compose up` from your project folder. |
| 40 | ++ |
| 41 | +[source,shell,subs="attributes+,+macros"] |
| 42 | +---- |
| 43 | +docker-compose up -d |
| 44 | +---- |
| 45 | ++ |
| 46 | +The `-d` flag starts the container in detached mode. |
| 47 | + |
| 48 | +[role=label--recommended] |
| 49 | +[[docker-compose-secrets]] |
| 50 | +== Deploy a Neo4j server with Docker secrets |
| 51 | + |
| 52 | +It is advisable not to store sensitive information, such as the database username and password, in the _docker-compose.yml_ file. |
| 53 | +You can instead store your credentials in files and use them in your _docker-compose.yml_ file without exposing their values. |
| 54 | + |
| 55 | +. Create a file, for example, _neo4j_auth.txt_, containing the username and password for the Neo4j server to be used as a Docker secret. |
| 56 | ++ |
| 57 | +[source,text,subs="attributes"] |
| 58 | +---- |
| 59 | +neo4j:your_password |
| 60 | +---- |
| 61 | +. Prepare your _docker-compose.yml_ file using the following example. |
| 62 | +For more information, see the Docker Compose official documentation on https://docs.docker.com/compose/compose-file/#service-configuration-reference[Docker Compose specification]. |
| 63 | ++ |
| 64 | +.Example of a _docker-compose.yml_ file |
| 65 | +[source,yaml,subs="attributes+,+macros"] |
| 66 | +---- |
| 67 | +services: |
| 68 | + neo4j: |
| 69 | + image: neo4j:latest |
| 70 | + volumes: # <1> |
| 71 | + - /$HOME/neo4j/logs:/logs |
| 72 | + - /$HOME/neo4j/config:/config |
| 73 | + - /$HOME/neo4j/data:/data |
| 74 | + - /$HOME/neo4j/plugin:/plugins |
| 75 | + environment: |
| 76 | + - NEO4J_AUTH_FILE=/run/secrets/neo4j_auth_file # <2> |
| 77 | + ports: |
| 78 | + - "7474:7474" |
| 79 | + - "7687:7687" |
| 80 | + restart: always |
| 81 | + secrets: |
| 82 | + - neo4j_auth_file #<3> |
| 83 | +secrets: |
| 84 | + neo4j_auth_file: # <4> |
| 85 | + file: ./neo4j_auth.txt # <5> |
| 86 | +---- |
| 87 | +<1> Mount the _/$HOME/neo4j/<..>:_ directories to local directories on your host machine to store logs, configuration, data, and plugins. |
| 88 | +<2> Path to the file where the value for the `NEO4J_AUTH` environment variable can be found. |
| 89 | +<3> The name of the secret, for example `neo4j_auth_file`. |
| 90 | +<4> Path to the _neo4j_auth.txt_ file. |
| 91 | +<5> The name of the secret in the `neo4j` service. |
| 92 | ++ |
| 93 | +[WARNING] |
| 94 | +==== |
| 95 | +The secret value overrides the equivalent environment variable if they are both defined. |
| 96 | +So, for example, if you also define an environment variable `NEO4J_AUTH=neo4j/your_other_password` in the `environment` section of the `neo4j` service, the value of `NEO4J_AUTH_FILE` will be the one used. |
| 97 | +==== |
| 98 | + |
| 99 | +. Deploy your Neo4j server by running `docker-compose up` from your project folder. |
| 100 | ++ |
| 101 | +[source,shell,subs="attributes+,+macros"] |
| 102 | +---- |
| 103 | +docker-compose up -d |
| 104 | +---- |
| 105 | ++ |
| 106 | +The `-d` flag starts the container in detached mode. |
0 commit comments