Run docker commands on all or some containers

  • Use the ps command with the q param to fetch the insance id and then apply the command:
    • docker {COMMAND TO RUN} $(docker ps -a -q)  -> for containers
    • docker {COMMAND TO RUN} $(docker images -q) -> for images
  • Examples:
    • Delete all stopped containers: docker rm $(docker ps -a -q)
    • Delete all unused images: docker rmi $(docker images -q)
    • Start all stopped containers: docker start $(docker ps -a -q)
    • Restart all containers: docker restart $(docker ps -a -q)
  • Print names of containers: docker ps | awk ‘{if(NR>1) print $NF}’ This commands avoids column name using NR>1 and prints the last column. So it uses the fact that las column is the one we are interested.
  • Reformat ps output format: docker ps –format ‘table {{.Names}}\t{{.Image}}’ Using format modifier we directly print only desired columns separating them using a given separetor (\t on this case)
  • Print only containers names without headers using format and tail: docker ps -a –format ‘table {{.Names}}’ |tail -n +2 Print only column names using format modifier and avoid column names using tail command to print from to line 2
  • For more elavorated filters:
    • docker  {COMMAND TO RUN} $(docker ps -a |grep {TEXT-TO-CAPTURE}|awk ‘{ print $1 }’)  where awk ‘{ print $1 }’ captures the container id value.
    • Remove all images with  “pattern” in name: docker rmi $(docker images -f=”reference=*pattern*” -q)

Run smartcontract using maven

Normal execution:
mvn exec:java -Dexec.mainClass=”path.to.chaincode” -Dexec.args=”-a pearIp:port-i chaincodeName:version
Debug mode:
  • On CommandLine:
    • mvnDebug.cmd exec:java -Dexec.mainClass=”path.to.chaincode” -Dexec.args=”-a pearIp:port-i chaincodeName:version
    • Set and edit options if defaults are not ok:
      MAVEN_DEBUG_OPTS=”-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000″
  • On intellij: new Remote connection.

Apprenders and formating a default java.util.logger

handlers=java.util.logging.ConsoleHandler
.level=INFO
java.util.logging.FileHandler.level = INFO
java.util.logging.FileHandler.pattern = log.%u.%g.txt
java.util.logging.SimpleFormatter.format= %1$tl:%1$tM:%1$tS %1$Tp %2$s %4$s: %5$s%n
java.util.logging.ConsoleHandler.level=INFO
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter

More info about SimpleFormatter: https://docs.oracle.com/javase/7/docs/api/java/util/logging/SimpleFormatter.html#SimpleFormatter()

More Info about formatting params:
https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html