You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.9 KiB

  1. # Docker
  2. ## Prerequisites
  3. The only prerequisites are:
  4. 1. This repo, and
  5. 2. Docker
  6. Building the docker image pulls in all the dev dependencies to build loop within the image itself. Having a `go` development environment is not required.
  7. ## Building the Docker Image
  8. The docker image can be built using this command within the `loop` directory:
  9. ```
  10. docker build --tag loop .
  11. ```
  12. This command pulls down a `go` build container, builds `loop` and `loopd` executables, then publishes those binaries to a fresh, smaller image, and marks that image with the tag 'loop'.
  13. ## Running the Docker Image
  14. The docker image contains:
  15. * The binary `loopd`, at `/go/bin/loopd`
  16. * The binary `loop`, at `/go/bin/loop`
  17. Docker is very flexible so you can use that information however you choose. This guide isn't meant to be prescriptive.
  18. ### Example: Running loopd
  19. One way of running `loopd` is
  20. ```
  21. docker run --rm -it --name loopd -v $HOME/.lnd:/root/.lnd -v $HOME/.loop:/root/.loop loop:latest loopd --network=testnet <my-lnd-ip-address>:10009
  22. ```
  23. Things to note from this docker command:
  24. * You can stop the server with Control-C, and it'll clean up the associated stopped container automatically.
  25. * The name of the running container is 'loopd' (which you may need to know to run the `loop` command).
  26. * The '.lnd' directory in your home directory is mapped into the container, and `loopd` will look for your tls.cert and macaroon in the default locations. If this isn't appropriate for your case you can map whatever directories you choose and override where `loopd` looks for them using additional command-line parameters.
  27. * The '.loop' directory in your home directory is mapped into the container, and `loopd` will use that directory to store some state.
  28. * You probably need to specify your LND server host and port explicitly, since by default `loopd` looks for it on localhost and there is no LND server on localhost within the container.
  29. * No ports are mapped, so it's not possible to connect to the running `loopd` from outside the container. (This is deliberate. You can map ports 8081 and 11010 to connect from outside the container if you choose.)
  30. ### Example: Running loop
  31. If you're using the example above to run `loopd`, you can then run the `loop` command inside that running container to execute loops. One way would be:
  32. ```
  33. docker exec -it loopd loop out --channel <channel-id-you-want-to-use> --amt <amount-you-want-to-loop-out>
  34. ```
  35. Things to note about this docker command:
  36. * `docker exec` runs a command on an already-running container. In this case `docker exec loopd` says effectively 'run the rest of this command-line as a command on the already-running container 'loopd'.
  37. * The `-it` flags tell docker to run the command interatively and act like it's using a terminal. This helps with commands that do more than just write to stdout.
  38. * The remainder `loop out --channel <channel-id-you-want-to-use> --amt <amount-you-want-to-loop-out>` is the actual loop command you want to run. All the regular `loop` documentation applies to this bit.
  39. ### A Handy Script
  40. If you're using the example above to run `loopd`, creating a script can simplify running `loop`.
  41. Create a file with the following contents:
  42. ```
  43. #!/usr/bin/env bash
  45. if [ -t 1 ] ; then
  46. TERMINAL_FLAGS="-it"
  47. fi
  48. docker exec $TERMINAL_FLAGS loopd loop "${@}"
  49. ```
  50. Call this script 'loop', put it somewhere in your $PATH, and make it executable. Then you can just run commands like:
  51. ```
  52. loop out --channel <channel-id-you-want-to-use> --amt <amount-you-want-to-loop-out>
  53. ```
  54. without having to remember (or use) the docker part explicitly.
  55. ## Caveats
  56. Running `loopd` the way shown above won't restart `loopd` if it is stopped or if the computer is restarted. You may want to investigate running the 'loop' container at startup, or when your LND server starts. (For example, `docker` has restart options, or grouping of containers via `docker-compose`.)