cancel
Showing results for 
Search instead for 
Did you mean: 

Docker container restart causes the container to hang and quit

gdantimi
Node

Hello,

 

I created a custom docker image in order to launch a wrapper script to load initial data. The first time I launch the container I kinda works, sometimes fails but I guess there is something cached or I don't wait enough for neo4j to be up.

The problem comes when I stop the container and i restart it. It downloads the plugins then it seems to hang and it fails to bring the process to foreground.

./wrapper.sh: line 57: fg: job has terminated

In /logs/debug.log there is no log when i restart the container. So it is hard to understand what's going on. Some permission issue?

 

Here my wrapper file

#!/bin/bash

# THANK YOU! Special shout-out to @marcellodesales on GitHub
# https://github.com/marcellodesales/neo4j-with-cypher-seed-docker/blob/master/wrapper.sh for such a great example script

# Log the info with the same format as NEO4J outputs
log_info() {
  # https://www.howtogeek.com/410442/how-to-display-the-date-and-time-in-the-linux-terminal-and-use-it-in-bash-scripts/
  # printf '%s %s\n' "$(date -u +"%Y-%m-%d %H:%M:%S:%3N%z") INFO  Wrapper: $1"  # Display UTC time
  printf '%s %s\n' "$(date +"%Y-%m-%d %H:%M:%S:%3N%z") INFO  Wrapper: $1"  # Display local time (PST/PDT)
  return
}

# Adapted from https://github.com/neo4j/docker-neo4j/issues/166#issuecomment-486890785
# Alpine is not supported anymore, so this is newer
# Refactoring: Marcello.deSales+github@gmail.com

# turn on bash's job control
# https://stackoverflow.com/questions/11821378/what-does-bashno-job-control-in-this-shell-mean/46829294#46829294
set -m

# Start the primary process and put it in the background
/docker-entrypoint.sh neo4j &

# Wait for Neo4j
log_info "Checking to see if Neo4j has started at http://${DB_HOST}:${DB_PORT}..."
wget --quiet --tries=20 --waitretry=10 -O /dev/null http://${DB_HOST}:${DB_PORT}
log_info "Neo4j has started 🤓"
log_info "Importing data with auth ${NEO4J_AUTH}"

# Import data
log_info  "Loading and importing Cypher file(s)..."
  for cypherFile in /var/lib/neo4j/import/*.data.cypher; do
      [ -f "$cypherFile" ] || break
      log_info "Running cypher ${cypherFile}"
      cat  ${cypherFile} | bin/cypher-shell -u ${NEO4J_USER} -p ${NEO4J_PASSWORD} --fail-fast --format plain
      log_info  "Renaming import file ${cypherFile}"
      mv  ${cypherFile}  ${cypherFile}.applied
  done

log_info  "Finished loading data"

log_info  "Running startup cypher script..."
  for cypherFile in /var/lib/neo4j/import/*.startup.cypher; do
      [ -f "$cypherFile" ] || break
      log_info "Running cypher ${cypherFile}"
      cat  ${cypherFile} | bin/cypher-shell -u ${NEO4J_USER} -p ${NEO4J_PASSWORD} --fail-fast --format plain
  done
log_info  "Finished running startup script"

# now we bring the primary process back into the foreground
# and leave it there
fg %1

And here my dockerfile

FROM neo4j

ENV NEO4J_USER=neo4j
ENV NEO4J_PASSWORD=s3cr3t
ENV NEO4J_AUTH=${NEO4J_USER}/${NEO4J_PASSWORD}
ENV NEO4JLABS_PLUGINS='["apoc", "graph-data-science"]'
ENV NEO4J_HOME='/var/lib/neo4j'
ENV DB_HOST='localhost'
ENV DB_PORT=7474
ENV NEO4J_dbms_logs_debug_level='DEBUG'
ENV NEO4J_dbms_logs_user_stdout__enabled='true'

EXPOSE 7474 7473 7687

COPY initial-data/ /var/lib/neo4j/import/

COPY ./docker-scripts/wrapper.sh wrapper.sh

ENTRYPOINT ["./wrapper.sh"]

 

1 REPLY 1

gdantimi
Node

It seems to happen with the latest version, when I switched to neo4j:4.2 then it started to work correctly.

 

I tried to run the clean images and both work, but using the wrapper script it seems to me that 4.4.10 has some issues in shutting down, maybe leaving some inconsistent state