Google Spreadsheet: build text with different columns - join

I have the following table
A1
A2
A3
A4
host1
host2
host3
host4
Within a single cell, i want to build command line for all of these hosts, for example let's say i want to execute "ls -la /etc" on all of these hosts. The way I am currently doing this is like that:
concatenate("ssh root#",A1,"'ls -la /etc'",char(10),"ssh root#",A2,"'ls -la /etc'",char(10)"ssh root#",A3,"'ls -la /etc'",char(10)"ssh root#",A4,"'ls -la /etc'",char(10))
There must be a more elegant way to do this however, right? It is important for me that all commands are listed within the same cell. I already looked into TEXTJOIN() and ARRAYFORMULA, but i was not able to do it.

Related

Delete docker images with same name

Server storing multiple docker images with same name but with different tags, I am finding the good command which will search docker images with same name, but with different tags, and delete all, saving only the newest.
Example.
TestImage:v1
TestImage:v2
TestImage:v3
TestImage:v4
The command will delete all images which have name "TestImage" but save TestImage:v4 (which is newest by date).
The actual command .
Provided you have the docker cli installed, the following should work:
image_ids=$(docker image ls "$name" -q | tail -n +2 | xargs)
docker image rm "$image_ids"
The first command loads all local images with the given name. Using the -q flag means that only the image ids are being outputted.
the tail program then skips the first one of these ids (in other words, starts reading at line 2). Since images are sorted from new to old, this means the newest image is skipped.
The xargs then brings all the outputted ids into the same line, so that docker can interpret them easily.
The ids obtained in that step may look something like this:
ae3c4906b72c 650d66a00131 18cac929dc4f
docker image rm will then remove all images with these ids.

My docker filesystem duplicates itself for no reason

My FS has been filled by my docker container (docker pull dependencytrack/apiserver). It seems it has duplicated itself in many subfolders.
find /var/lib/docker/overlay2/ -name alpine-1.10.2.jar | wc -l
1550
(answer should be closer to 1, I guess).
They all reside in /var/lib/docker/overlay2/[diff|merged]/<random_number1>/tmp/jetty-0_0_0_0-8080-dependency-track-apiserver_jar-dtrack-api-any-<random_number2>/webapp/WEB-INF/lib/
where random_number1 is fixed and random_number2 has many differents values.
Is this problem related to my image, or is it docker ? I don't really know how to proceed from here.

List docker containers by App using command line tool

How can I list docker containers by application? For example, assume that I have app1 (that has c1, c2, c3) and app2 (that has c4, c5) deployed. I can see c1, c2 and c3 are under app1 and c4 and c5 are under app2 using docker dashboard. But, if I do "docker ps", it returns a flat list of containers, I have no way to know which containers belong to which app? Below is an example.
As can be seen in docker dashboard on the left side, there are two applications, nginx-gohttp-master and demo, deployed in the docker environment. The first app has two containers and the second app has four containers, and the two apps are independent of each other. However, I only see a flat list of containers on the right side as listed by "docker ps". I would like to know how many apps are deployed and which containers belong to which app. How can I do that using a docker command line tool?
Thanks
By default, docker-compose adds some labels including com.docker.compose.project which contains the name of the compose app/project. You can get that output using docker ps with the --format option like so:
$ docker ps --format 'table {{.Label "com.docker.compose.project"}} {{.ID}} {{.Names}} {{.Command}} {{.Status}}'
project CONTAINER ID NAMES COMMAND STATUS
app1 1fd93328e69b app1_nginx_1 "/docker-entrypoint.…" Up 3 minutes
app2 9fe81391b961 app2_nginx_1 "/docker-entrypoint.…" Up 2 minutes
app3 d28fca61a184 app3_nginx_1 "/docker-entrypoint.…" Up 1 minutes
You can see some of the other labels that docker-compose applies here.
Check out filters
Filter running containers
docker ps --filter "name=nginx-gohttp-master"
Filter all containers (running + stopped)
docker ps -a --filter "name=nginx-gohttp-master"
Apparently there's no need for a wildcard character *, because = is not a direct exact-match string equality but a sub-string search.
For an exact match (which is not what you want in your question) you need to pipe the result into something else as discussed here.

How to use docker arguments as arguments to a function inside it

I am trying to get the arguments from the docker image and then I want to use that argument as an argument to the function inside the docker.
For example:
CMD ["python", "xyz.py","--input=/input_data","--output=/output_data"]
I want to enter the locations of input and output commandline
or
CMD ["python", "add.py","--input1=4","--input2=5"]
I want to enter 4 and 5 from command line to get the sum as a result, in this way I can generalize my docker very well.
How can i do this?
As far as I can understand, what you want is to create, in the second case, a container that adds two elements.
If I am right, and what you want to execute at the moment is something like:
docker run add:latest 4 6
What you have to do is a script with the python add.py and include it as ENTRYPOINT, not in the CMD. Then you could call: docker run add: latest 4 5 and get the sum of both.
The CMD can be overwritten in docker run. Look at this post:
http://www.johnzaccone.io/entrypoint-vs-cmd-back-to-basics/

GNU parallel to keep docker-compose in attached mode

I'm trying to run a bunch of docker-compose commands in parallel using GNU parallel. For some reason though, it looks like starting parallel force docker-compose in detached mode so I can't access the container output anymore.
I was hoping parallel would just keep docker-compose attached and print the output in order once the process is done.
Here's my command
echo 'tests/test_foo.py' | parallel -X docker-compose --project-name bar run --rm test py.test $*
Is there a way to force docker-compose to stay attached?
There is no detached mode for run, it should always print the log lines to the terminal. This seems to work for me with a single line of input.
However, calculating the container name is racy, so trying to run multiple instances like this may result in name conflict errors. You might need to use --name as an option to run to set a unique name for each.
You might also consider using pytest-xdist to run the tests in parallel inside a single test container.
Further to dnephin's answer, You can name each container with parallel's positional arguments so there is no naming contention
echo -e "1\ttest1\n2\ttest2\n3\ttest3" | parallel -X --colsep '\t' docker-compose run --name proj{1} web echo {2}
In this demo the tab is used to separate the first field, used for the name and the second string used for the command.
You either need to use existing fields from tests/test_foo.py for the names or add this additional information if what you have in that file is not unique.

Resources