Skip to content

Commit

Permalink
docs: 📝 reference for build and run in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
heldrida committed Sep 18, 2023
1 parent de91a30 commit 91f7d81
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 1 deletion.
6 changes: 5 additions & 1 deletion guides/Node Operators/running-a-node-in-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ At time of writing, this is how the project root looks like (e.g. use the [ls](h
└── target
```

### Install Docker on Ubuntu
### Install Docker

:::tip
To keep our guide short, we're using Ubuntu Linux. You'll have to make the required tweaks for your preferred Linux Distro. Find the list of support operating systems [here](/docs/node/requirements#server).
:::

First, update the existing list of packages:

Expand Down
181 changes: 181 additions & 0 deletions references/Docker/build-and-run-in-docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
---
title: Build and run in Docker
slug: build-and-run-in-docker
hide_title: true
tags:
- references
- help
- docker
- build
- image
- container
---

import Author from '@site/src/components/Author';
import GitCloneOptions from '../../guides/partials/_git-clone-options.mdx';

## Clone the source code locally

<GitCloneOptions />

## Change directory to Lightning source code

```sh
cd ~/fleek-network/lightning
```

## Install Docker

:::tip
We're using Ubuntu Linux. You'll have to make the required tweaks for your preferred Linux Distro. Find the list of support operating systems [here](/docs/node/requirements#server).
:::

```sh
sudo apt update
```

Next, install the required packages to let apt use packages over HTTPS:

```sh
sudo apt install \
apt-transport-https \
ca-certificates \
software-properties-common
```

Add the GPG key for the official Docker repository to your system:

```sh
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
```

Add the Docker repository to apt sources and update the package database with the Docker packages from the new added repository:

```sh
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu jammy stable"
```

Set to install from the Docker repo instead of the default Ubuntu repo:

```sh
apt-cache policy docker-ce
```

Finally, install Docker:

```sh
sudo apt install docker-ce
```

Once complete you should be able to run it via the CLI, as such:

```sh
docker -v
```

Here's the output (versions might differ a bit from the time of writing):

```sh
Docker version 24.0.6, build ed223bc
```

## Docker setup verification

The following command's output will indicate if Docker's working correctly:

```sh
sudo docker run hello-world
```

You should get a "Hello from Docker!".

## Create the Dockerfile

```sh
touch Dockerfile
```
Copy and paste to the Dockerfile the following content:

```sh
FROM rust:latest as builder
ARG PROFILE=release
WORKDIR /lightning

RUN apt-get update
RUN apt-get install -y \
build-essential \
cmake \
clang \
pkg-config \
libssl-dev \
gcc \
protobuf-compiler

RUN --mount=type=cache,target=/usr/local/cargo/registry \
cargo install cargo-strip

COPY . .
ENV RUST_BACKTRACE=1

RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/lightning/target \
cargo build --profile $PROFILE --bin lightning-node \
&& cargo strip \
&& mv /lightning/target/release/lightning-node /lightning-node

FROM ubuntu:latest

RUN DEBIAN_FRONTEND=noninteractive apt-get update -yq && \
DEBIAN_FRONTEND=noninteractive apt-get install -yq \
libssl-dev \
ca-certificates

# Get compiled binaries from builder's cargo install directory
COPY --from=builder /lightning/target/release/lightning-node /usr/local/bin/lgtn

ENTRYPOINT ["lgtn", "run"]
```

## Build the Docker image

Build the image named as `lightning` from our Dockerfile:

```sh
sudo docker build -t lightning -f ./Dockerfile .
```

## Generate keys

```sh
sudo docker exec -it lightning-cli lgtn keys generate
```

## Docker Container

```sh
sudo docker run \
-p 4069:4069 \
-p 4200:4200 \
-p 6969:6969 \
-p 18000:18000 \
-p 18101:18101 \
-p 18102:18102 \
-v $HOME/.lightning/:/root/.lightning/:rw \
--name lightning-cli \
-it lightning
```

## View logs

To view the logs of a Docker container in real time, use the following command:

```sh
sudo docker logs -f lightning-cli
```

<Author
name="Helder Oliveira"
image="https://github.com/heldrida.png"
title="Software Developer + DX"
url="https://github.com/heldrida"
/>

0 comments on commit 91f7d81

Please sign in to comment.