Docker: How can I have sqlite db changes persist to the db file? -


from golang:1.8  add . /go/src/beginnerapp  run go -u github.com/gorilla/mux  run go github.com/mattn/go-sqlite3  run go install beginnerapp/  volume /go/src/beginnerapp/local-db  workdir /go/src/beginnerapp  entrypoint /go/bin/beginnerapp  expose 8080 

the sqlite db file in local-db directory don't seem using volume command correctly. ideas how can have db changes sqlite db file persisted?

i don't mind if volume mounted before or after build.

i tried running following command

user@cardboardlaptop:~/go/src/beginnerapp$ docker run -p 8080:8080 -v ./local-db:/go/src/beginnerapp/local-db beginnerapp 

docker: error response daemon: create ./local-db: "./local-db" includes invalid characters local volume name, "[a-za-z0-9][a-za-z0-9_.-]" allowed. if intended pass host directory, use absolute path.

edit: works using /absolutepath/local-db instead of relative path ./local-db

you not mounting volumes in dockerfile. volume tells docker content on directories can mounted via docker run --volumes-from

you're right. docker doesn't allow relative paths on volumes on command line.

run docker using absolute path:

docker run -v /host/db/local-db:/go/src/beginnerapp/local-db

your db persisted in host file /host/db/local-db

if want use relative paths, can make work docker-compose "volumes" tag:

volumes:   - ./local-db:/go/src/beginnerapp/local-db 

you can try configuration:

  • put dockerfile in directory, (e.g. /opt/docker/myproject)
  • create docker-compose.yml file in same path this:
version: "2.0" services:   myproject:     build: .     volumes:       - "./local-db:/go/src/beginnerapp/local-db" 
  • execute docker-compose -d myproject in same path.

your db should stored in /opt/docker/myproject/local-db

just comment. content of local-db (if any) replaced content of ./local-db path (empty). if container have information (initialized database) idea copy docker cp or include init logic on entrypoint or command shell script.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -