Some useful Docker Commands for Service Providers

Okay, so I am assuming here that you already followed instructions and are running blobber(s) and/or a miner/sharder for the 0chain network.

Managing Docker Containers

Lets start with seeing what docker processes are running

docker ps -a

Here is an example output

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                      NAMES
cf11e7c1c46c        nginx:latest        "/docker-entrypoint.…"   2 weeks ago         Up 2 weeks          0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   https_web_1
a6da8f361cff        blobber             "./bin/blobber --por…"   2 weeks ago         Up 6 days           0.0.0.0:5051->5051/tcp                     blobber1_blobber_1
bc17b0b7e56a        validator           "./bin/validator --p…"   2 weeks ago         Up 2 weeks          0.0.0.0:5061->5061/tcp                     blobber1_validator_1
164da1687086        postgres:11         "docker-entrypoint.s…"   2 weeks ago         Up 2 weeks          5432/tcp                                   blobber1_postgres_1

As you can see, you can see other useful information such as port numbers in addition to the status of each container

Now if you add -a parameter, you will also see inactive tasks

docker kill $(docker ps -a)
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS                   PORTS                                      NAMES
1ea8ad192665        certbot/certbot:latest   "certbot certonly --…"   2 weeks ago         Exited (1) 2 weeks ago                                              https_certbot_1
cf11e7c1c46c        nginx:latest             "/docker-entrypoint.…"   2 weeks ago         Up 2 weeks               0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   https_web_1
a6da8f361cff        blobber                  "./bin/blobber --por…"   2 weeks ago         Up 6 days                0.0.0.0:5051->5051/tcp                     blobber1_blobber_1
bc17b0b7e56a        validator                "./bin/validator --p…"   2 weeks ago         Up 2 weeks               0.0.0.0:5061->5061/tcp                     blobber1_validator_1
164da1687086        postgres:11              "docker-entrypoint.s…"   2 weeks ago         Up 2 weeks               5432/tcp                                   blobber1_postgres_1

So you can see the certbot container exited 2 weeks ago. Although inactive, it is still present.

You might want to list running containers of a particular type. So all the blobber containers have blobber in the name. (The NAMES field is over to the right, you may need to scrollbar over to see it). For example, lets try

docker ps -f name=blobber

You can see that only the ones matching will result.

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
a6da8f361cff        blobber             "./bin/blobber --por…"   2 weeks ago         Up 6 days           0.0.0.0:5051->5051/tcp   blobber1_blobber_1
bc17b0b7e56a        validator           "./bin/validator --p…"   2 weeks ago         Up 2 weeks          0.0.0.0:5061->5061/tcp   blobber1_validator_1
164da1687086        postgres:11         "docker-entrypoint.s…"   2 weeks ago         Up 2 weeks          5432/tcp                 blobber1_postgres_1

So the CONTAINER IDs are the IDs we are most interested in. With these, we can control the processes in a variety of ways

docker stop <PROCESSID>

Will stop the process(es)

docker kill <PROCESSID>

Will kill the process if it does not respond gracefully to the stop command

docker rm <PROCESSID>

Will remove the container. This is required if you need to update the software as you cannot have two instances of the same container running at the same time. You will need to list using -a above to highlight inactive containers to remove them.

docker start <PROCESSID>

Will (re)start a stopped container. If a container has unexpectedly stopped for some reason, this may restart it, but there must be an underlying reason why, so that has to be investigated. Some containers perform a purpose then stop themselves which is fine. In the above examples, the certbot container is such a container.

Rather than individually cut and paste container ids, you might wish to perform ‘bulk’ tasks. This can be done by using the output from one command as a list for another command. First lets get a list of blobber containers again, but this time, lets only get the process ids by adding the -q parameter

docker ps -q -f name=blobber

You should only get the Process IDs

a6da8f361cff
bc17b0b7e56a
164da1687086

So We can inject these into a command to save manipulating each one manually

*NOTE: DO NOT DO THESE COMMANDS ON A LIVE SYSTEM UNLESS YOU ACTUALLY MEAN TO*

docker stop $(docker ps -q -f name=blobber)

Would stop all active containers with name matching blobber

docker rm $(docker ps -a -q -f name=blobber)

Would remove all inactive containers with name matching blobber

Examples

These are just a basic idea to understand typical use. For mainnet, more detailed instructions will be provided. For example, to actually update/restart blobbers you may need to update/restart other containers also.
So lets say we need to change a configuration on our blobber. We might want to stop the containers, then restart them.

docker stop $(docker ps -q -f name=blobber)
docker start $(docker ps -q -a -f name=blobber)

If there is a blobber software update, it will be a little more involved.

docker stop $(docker ps -q -f name=blobber)

Will stop containers

docker rm $(docker ps -q -a -f name=blobber)

Will remove them. (they should be inactive now). If any containers fail to remove you may need to relist and kill them first
*UPDATE SOFTWARE*
*RESTART*

Okay, so now hopefully you have an idea of how containers are handled, here are a few more useful commands

docker network ls

Will list all the network connections

docker logs <CONTAINERID>

Will give logs from that container

ADDED

docker image prune

Will remove all dangling images.

docker image prune -a

Will remove all unused images (e.g. not referenced by any container), not just the dangling ones.

These will be necessary to completely clean down a system to install a fresh build (without a complete system reformat).

Ping me a message on TG if you have any further tips to add to this tutorial
@sculptex