Install LayerG with Docker Compose
Docker is the quickest way to download and start developing with LayerG. By using Docker you are able to:
- Install to a pristine environment
- Easily install and run the CockroachDB or PostgreSQL database for LayerG
- Take snapshots, remove, and re-install LayerG without affecting your primary operating system
- Enjoy a quick and simplified installation experience regardless of your OS
Following this guide, you will use Docker Compose to quickly and easily define all the necessary services and run your local development instance of LayerG.
Prerequisites
Before proceeding ensure that you have installed Docker Desktop.
Linux Users
Docker Desktop is only available for Mac and Windows. You must install Docker Engine and Docker Compose individually for your distribution.
Running LayerG
- Start by creating a directory where your LayerG server will sit, for example
Desktop/LayerG
. - In this folder create a
docker-compose.yml
file and open it using your preferred text editor. - Layerg Labs provides two YML files for use: using either PostgreSQL or CockroachDB as the database.
docker-compose-postgres.yml
version: '3'
services:
postgres:
container_name: postgres
image: postgres:12.2-alpine
environment:
- POSTGRES_DB=LayerG
- POSTGRES_PASSWORD=localdb
volumes:
- data:/var/lib/postgresql/data
expose:
- "8080"
- "5432"
ports:
- "5432:5432"
- "8080:8080"
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres", "-d", "LayerG"]
interval: 3s
timeout: 3s
retries: 5
LayerG:
container_name: LayerG
image: registry.layerglabs.com/layerglabs/LayerG:3.22.0
entrypoint:
- "/bin/sh"
- "-ecx"
- >
/LayerG/LayerG migrate up --database.address postgres:localdb@postgres:5432/LayerG &&
exec /LayerG/LayerG --name LayerG1 --database.address postgres:localdb@postgres:5432/LayerG --logger.level DEBUG --session.token_expiry_sec 7200
restart: always
links:
- "postgres:db"
depends_on:
postgres:
condition: service_healthy
volumes:
- ./:/LayerG/data
expose:
- "7349"
- "7350"
- "7351"
ports:
- "7349:7349"
- "7350:7350"
- "7351:7351"
healthcheck:
test: ["CMD", "/LayerG/LayerG", "healthcheck"]
interval: 10s
timeout: 5s
retries: 5
volumes:
data:
docker-compose-cockroach.yml
version: '3'
services:
cockroachdb:
image: cockroachdb/cockroach:latest-v23.1
command: start-single-node --insecure --store=attrs=ssd,path=/var/lib/cockroach/
restart: "no"
volumes:
- data:/var/lib/cockroach
expose:
- "8080"
- "26257"
ports:
- "26257:26257"
- "8080:8080"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health?ready=1"]
interval: 3s
timeout: 3s
retries: 5
LayerG:
image: registry.layerglabs.com/layerglabs/LayerG:3.22.0
entrypoint:
- "/bin/sh"
- "-ecx"
- >
/LayerG/LayerG migrate up --database.address root@cockroachdb:26257 &&
exec /LayerG/LayerG --name LayerG1 --database.address root@cockroachdb:26257 --logger.level DEBUG --session.token_expiry_sec 7200 --metrics.prometheus_port 9100
restart: "no"
links:
- "cockroachdb:db"
depends_on:
cockroachdb:
condition: service_healthy
prometheus:
condition: service_started
volumes:
- ./:/LayerG/data
expose:
- "7349"
- "7350"
- "7351"
- "9100"
ports:
- "7349:7349"
- "7350:7350"
- "7351:7351"
healthcheck:
test: ["CMD", "/LayerG/LayerG", "healthcheck"]
interval: 10s
timeout: 5s
retries: 5
prometheus:
image: prom/prometheus
entrypoint: /bin/sh -c
command: |
'sh -s <<EOF
cat > ./prometheus.yml <<EON
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
- job_name: LayerG
metrics_path: /
static_configs:
- targets: ['LayerG:9100']
EON
prometheus --config.file=./prometheus.yml
EOF'
ports:
- '9090:9090'
volumes:
data:
Copy and paste the contents of your preferred option into your docker-compose.yml
file.
Windows Users
You must edit the LayerG:volumes:
entry in your docker-compose.yml
file so that it looks like the following: /c/Users/<username>/projects/docker:/LayerG/data
.
- Open a Terminal window and navigate to your LayerG directory. For example:
cd desktop/LayerG
- To pull all required images and start your application, run the following:
docker compose up
- Congratulations! Your LayerG server is now up and running, available at
127.0.0.1:7350
.
LayerG containers running
Use the Open in Visual Studio Code button (or that for your IDE) to edit your docker-compose.yml
file directly.
LayerG Console
You can also access the LayerG Console by navigating your browser to 127.0.0.1:7351:
![LayerG console]
LayerG console
When prompted to login, the default credentials are admin:password
. These can be changed via configuration file or command-line flags.
Configuration File
There are many configuration options available that you can customize for your LayerG server. You can create a YML file for all configurations you want to set, and pass that file to your Docker containers.
First you will need to make a local storage volume available to Docker:
- Open your
docker-compose.yml
file in your preferred text editor. - Edit the
LayerG:volumes:
entry to specify your desired volume. For example, to create a/data
folder in ourdesktop/LayerG
directory used above, which would be available atLayerG/data
in the Docker container, it would look like the following:
volumes:
- ./data:/LayerG/data
- Save the changed file and restart your Docker containers for the change to take effect. From your Terminal:
docker compose restart
- Next, create your custom configuration file, for example
my-config.yml
, and place it in the/data
folder that you made available to Docker, above.
my-config.yml
name: LayerG-node-1
data_dir: "./data/"
logger:
stdout: false
level: "warn"
file: "/LayerG/data/logfile.log"
console:
port: 7351
username: "my_user"
password: "my_password"
- Open your
docker-compose.yml
file again, this time to edit theLayerG:entrypoint
entry to add the--config
flag pointing to your configuration file. It should look like this:
LayerG:
entrypoint: - "/bin/sh" - "-ecx" - >
/LayerG/LayerG migrate up --database.address root@cockroachdb:26257 &&
/LayerG/LayerG --config /LayerG/data/my-config.yml
- Save the changed file and restart your Docker containers for the change to take effect. From your Terminal:
docker compose restart
Next steps
With your LayerG server now up and running with the desired configuration, you can get started with your preferred client SDK.