Restart Axon Server Container with Previous Data

PROBLEM: I start Axon server as Docker Container. Volumes are mounted outside to my host machine in docker-compose.yml:

version: '3.7' 
services:
  axon_server:
    image: 'axoniq/axonserver'
    ports: 
      - '8024:8024'
      - '8124:8124'
    hostname: localhost
    volumes: 
      - /data/axon:/data
      - /data/axon/eventdata:/data/eventdata
    privileged: yes

When I remove a Docker-container and build it again from image, all previously stored events are cleared.

QUESTION: How to restart Axon-server as Docker-container with previously saved data?

empty.png

Andrey,
glad to see you found the solution already. Note that on Linux (and MacOS) you can also use named volumes. The notation you are using here (with “:”) is translated to direct volume mounts, so they won’t show up if you use “docker volume ls”.

BTW I would strongly advise against setting the container’s hostname to “localhost”, as that is a reserved name. You can instead add another volume for “/config” and put a file “axonserver.properties” in there with “axoniq.axonserver.hostname=localhost”. This will do what you want, without confusing the rest of Docker. Another way to achieve this result would be to define a secret for the properties file and mount that into the “/config” directory:

version: ‘3.3’
services:
axonserver:
image: axoniq/axonserver
hostname: axonserver
volumes:

  • axonserver-data:/data

  • axonserver-events:/eventdata
    secrets:

  • source: axonserver-properties

target: /config/axonserver.properties
ports:

  • ‘8024:8024’

  • ‘8124:8124’
    networks:

  • axon-network

volumes:
axonserver-data:

driver: local
driver_opts:
o: bind
type: none
device: /data/axon
axonserver-events:
driver: local
driver_opts:
o: bind
type: none
device: /data/axon/eventdata

networks:

axon-network:

secrets:
axonserver-properties:
file: ./axonserver.properties

Cheers,
Bert Laverman