beancount / ledger2beancount

Ledger to Beancount text-based converter
GNU General Public License v3.0
79 stars 15 forks source link

feat(dockerfile): initial commit of Dockerfile #239 #240

Closed dennislwm closed 3 years ago

dennislwm commented 3 years ago

Run ledger2beancount from a Docker image. Fix #239.

To build the Docker image from Dockerfile:

DOCKER_BUILDKIT=1 docker image build -t <IMAGENAME> .

To run ledger2beancount from the above image:

--- copy and paste into bash script ---

#-------------------------------------------------------------------------
# Usage:  docker run -rm -v <hostdir>:<containerdir>:rw <image> <FILE>
#   hostdir is the host directory that contains your ledger files
#   containerdir is an empty container directory for the app to read/write
#   image is the Docker image name
#   FILE is the ledger file name
if [ -z $1 ]; then
    echo "Run ledger2beancount from a Docker image"
    echo "Usage:"
    echo "  $0 <hostdir> <image> <FILE>"
    echo "  hostdir Use absolute path"
    exit
fi

docker run --rm -v $1:/usr/ledger2beancount/docker:rw $2 docker/$3

--- end ---

tbm commented 3 years ago

thank you. Any reason you don't use ubuntu:latest btw?

dennislwm commented 3 years ago

thank you. Any reason you don't use ubuntu:latest btw?

No reason, you can change to latest if you want.

tbm commented 3 years ago

docker run --rm -v $1:/usr/ledger2beancount/docker:rw $2 docker/$3

It seems that docker run --rm IMAGE is enough to run. Is there a reason not to do that?

tbm commented 3 years ago

I applied this manually. Thank you!

dennislwm commented 3 years ago

-v $1:/usr/ledger2beancount/docker:rw

mounts the host directory to docker container

This is because apps within the docker container cannot read or write to host files by default.

so that we can run read ledger files and write to beancount files outside the docker container.

tbm commented 3 years ago

Thanks again @dennislwm