# Manage node

# With Docker

This is only a short summary from the fantastic docs.docker.com documentation website. Please visit it for more indepth information.

# Visualization

docker-compose bundles many services that are started together and interact together. In our case we have the services: GNY Blockchain Node (a node.js app) and a database (postgres) service. Each of this services is a separate docker container.

postgresdb GNY Blockchain

This two services are based off their respective docker images postgres:9.6.12 and gny/blockchain.

# Docker Images

A docker image is like a cookie cutter which can cut cookies (instantiate containers). From one image we can create exactly the same program, without the need to install or provide all libraries a program depends upon.

docker-db-image docker-node-image

From an image we can create multiple containers.

docker-db-image-multiple-instances docker-node-image-multiple-instances

# Docker networks

docker-compose creates automatically a network where only the services inside the docker-compose file can communicate. This is represented by the grey box. We can configure which service ports from the containers are visible on the host machine. The postgres database port is not reachable from the host machine. Only the GNY Blockchain service can access the postgres database service. The GNY Blockchain ports (4096 and 4097) are mapped to the host machine.

This is the beauty of docker-compose. We can specify all services that should work together and with one command we can start|stop|pause all services.

# Docker-Compose Lifecycle

# Docker-Compose 101

# Create and Start all services

sudo docker-compose --file docker-compose.yml up
1

This command will print all container messages to screen: docker_compose_up_console_output

# Create and Start all services

sudo docker-compose --file docker-compose.yml up --detach
1

This command runs all services in background. See logs command to see the logs of the services in the background.

docker_compose_up_console_background

# Start all services

This can only be executed if the docker-compose network and all containers were created previously. For example after an docker-compose stop.

sudo docker-compose --file docker-compose.yml start
1

docker_compose_start_error

docker_compose_start_success

# Check status of services

sudo docker-compose --file docker-compose.yml ps
1

docker_compose_ps

# Stop all services

sudo docker-compose --file docker-compose.yml stop
1

docker_compose_stop

# Stop and Remove

This removes the docker-compose network and volumes that were created.

sudo docker-compose --file docker-compose.yml down --volumes
1

# Docker 101

# Images

# Show all images

sudo docker image ls
1

# Get bash into image

sudo docker run -it <imageId> /bin/bash
1

# Containers

# Show status of running containers

sudo docker ps --all
1

# Show status of containers of a docker-compose file

sudo docker-compose --file docker-compose.yml ps
1

# Bash into running container

sudo docker exec -it <containerId> /bin/bash
1

# Delete

# Stop all running containers

sudo docker stop $(sudo docker ps --all --quiet)
1

# Delete all stopped containers

sudo docker rm $(sudo docker ps --all --quiet)
1