Код: Выделить всё
FROM neo4j:latest
# Copy the script into the container
COPY start-neo4j.sh /start-neo4j.sh
# Make the script executable
RUN chmod +x /start-neo4j.sh
# Run the script as the container's main command
CMD ["/start-neo4j.sh"]
Сценарий запуска выглядит следующим образом:
Код: Выделить всё
#!/bin/bash
# Ensure any failure in the script stops the script
echo "Starting Neo4j with NEO4J_AUTH set to: $NEO4J_AUTH"
# Start Neo4j in the foreground
exec neo4j console
Код: Выделить всё
-p 8123:7687 \
-p 8124:7474 \
-e NEO4J_AUTH=neo4j/1234567890 \
--user $(id -u):$(id -g) \
my-neo4j:latest
Сейчас я сижу за этим и не могу понять, что я сделал не так, поэтому любые баллы хороши!
Мой код для входа:
Код: Выделить всё
from neo4j import GraphDatabase
from neo4j.exceptions import ServiceUnavailable
def connect_to_neo4j(uri="bolt://localhost:8123", user="neo4j", password="1234567890"):
try:
# Create the driver
driver = GraphDatabase.driver(uri, auth=(user, password))
# Verify the connection
with driver.session() as session:
result = session.run("RETURN 'Connected!' as message")
print(result.single()['message'])
return driver
except ServiceUnavailable:
print("Failed to connect to Neo4j. Make sure the database is running.")
return None
except Exception as e:
print(f"An error occurred: {str(e)}")
return None
# Connect to the database
driver = connect_to_neo4j(password="1234567890")
# Don't forget to close the driver when you're done
if driver:
driver.close()
И логи из докера:
Код: Выделить всё
Starting Neo4j with NEO4J_AUTH set to: neo4j/1234567890
Directories in use:
home: /var/lib/neo4j
config: /var/lib/neo4j/conf
logs: /logs
plugins: /var/lib/neo4j/plugins
import: /var/lib/neo4j/import
data: /var/lib/neo4j/data
certificates: /var/lib/neo4j/certificates
licenses: /var/lib/neo4j/licenses
run: /var/lib/neo4j/run
Starting Neo4j.
2025-01-16 15:15:53.874+0000 INFO Logging config in use: File '/var/lib/neo4j/conf/user-logs.xml'
2025-01-16 15:15:53.891+0000 INFO Starting...
2025-01-16 15:15:55.069+0000 INFO This instance is ServerId{76436336} (76436336-1904-4f6f-a898-71082cd5bf7e)
2025-01-16 15:15:56.335+0000 INFO ======== Neo4j 5.26.0 ========
2025-01-16 15:15:59.524+0000 INFO Anonymous Usage Data is being sent to Neo4j, see https://neo4j.com/docs/usage-data/
2025-01-16 15:15:59.610+0000 INFO Bolt enabled on 0.0.0.0:7687.
2025-01-16 15:16:00.315+0000 INFO HTTP enabled on 0.0.0.0:7474.
2025-01-16 15:16:00.316+0000 INFO Remote interface available at http://localhost:7474/
2025-01-16 15:16:00.319+0000 INFO id: F5093BC561A00396AE5C94FA9F710E9085F0EA09F30D6B5B087DE9CC1AF9C7EF
2025-01-16 15:16:00.319+0000 INFO name: system
2025-01-16 15:16:00.319+0000 INFO creationDate: 2025-01-16T15:15:57.733Z
2025-01-16 15:16:00.320+0000 INFO Started.
2025-01-16 15:16:03.399+0000 WARN [bolt-0] The client is unauthorized due to authentication failure.
Подробнее здесь: https://stackoverflow.com/questions/793 ... ot-working
Мобильная версия