Issue in removing docker images remotely on CentOS
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I've installed a Kubernetes cluster using Rancher on 5 different CentOS nodes (let's say node1, node2, ..., node5). For our CI run, we need to clean up stale docker images before each run. I created a script that runs on node1, and password-less ssh is enabled from node1 to rest of the nodes. The relevant section of the script looks something like below:
#!/bin/bash
helm ls --short --all | xargs -L1 helm delete --purge
echo "Deleting old data and docker images from Rancher host node."
rm -rf /var/lib/hadoop/* /opt/ci/*
docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f
hosts=(node2 node3 node4 node5)
for host in ${hosts[*]}
do
echo "Deleting old data and docker images from ${host}"
ssh root@${host} docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f
ssh root@${host} rm -rf /var/lib/hadoop/* /opt/ci/*
done
echo "All deletions are complete! Proceeding with installation."
sleep 2m
Problem is, while the docker rmi
command inside the for loop runs for all other 4 nodes, I get the error Error: No such image: <image-id>
for each of the images. But if I execute same command on that node, it succeeds. I'm not sure what's the issue here. Any help is appreciated.
linux bash docker

add a comment |
I've installed a Kubernetes cluster using Rancher on 5 different CentOS nodes (let's say node1, node2, ..., node5). For our CI run, we need to clean up stale docker images before each run. I created a script that runs on node1, and password-less ssh is enabled from node1 to rest of the nodes. The relevant section of the script looks something like below:
#!/bin/bash
helm ls --short --all | xargs -L1 helm delete --purge
echo "Deleting old data and docker images from Rancher host node."
rm -rf /var/lib/hadoop/* /opt/ci/*
docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f
hosts=(node2 node3 node4 node5)
for host in ${hosts[*]}
do
echo "Deleting old data and docker images from ${host}"
ssh root@${host} docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f
ssh root@${host} rm -rf /var/lib/hadoop/* /opt/ci/*
done
echo "All deletions are complete! Proceeding with installation."
sleep 2m
Problem is, while the docker rmi
command inside the for loop runs for all other 4 nodes, I get the error Error: No such image: <image-id>
for each of the images. But if I execute same command on that node, it succeeds. I'm not sure what's the issue here. Any help is appreciated.
linux bash docker

Add quotes to ssh command. Thedocker images
is running on the remote machine but the rest the command beginninggrep localhost
is running on the local machine where you executed the script.
– Zaboj Campula
Jan 3 at 9:57
I think that might not be an issue. Actually I executed a partial command from node1 against node3,ssh root@node3 docker images | grep localhost | awk '{print $3}'
and it listed down all image-ids present in node3
– Bitswazsky
Jan 3 at 10:04
2
sure it prints images in node 3. Becausedocker images
is executes at node 3. Then the output is transferred to node1 and grep and awk just filter the text data at node1. But when you try delete an image then you need to do it at node3. Tryssh root@${host} "docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f"
– Zaboj Campula
Jan 3 at 10:10
@Zaboj Thanks a lot. That solved the issue.
– Bitswazsky
Jan 3 at 10:16
1
As an aside,awk '/localhost/ { print $3 }'
gets rid of the useless use ofgrep
.
– tripleee
Jan 3 at 10:20
add a comment |
I've installed a Kubernetes cluster using Rancher on 5 different CentOS nodes (let's say node1, node2, ..., node5). For our CI run, we need to clean up stale docker images before each run. I created a script that runs on node1, and password-less ssh is enabled from node1 to rest of the nodes. The relevant section of the script looks something like below:
#!/bin/bash
helm ls --short --all | xargs -L1 helm delete --purge
echo "Deleting old data and docker images from Rancher host node."
rm -rf /var/lib/hadoop/* /opt/ci/*
docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f
hosts=(node2 node3 node4 node5)
for host in ${hosts[*]}
do
echo "Deleting old data and docker images from ${host}"
ssh root@${host} docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f
ssh root@${host} rm -rf /var/lib/hadoop/* /opt/ci/*
done
echo "All deletions are complete! Proceeding with installation."
sleep 2m
Problem is, while the docker rmi
command inside the for loop runs for all other 4 nodes, I get the error Error: No such image: <image-id>
for each of the images. But if I execute same command on that node, it succeeds. I'm not sure what's the issue here. Any help is appreciated.
linux bash docker

I've installed a Kubernetes cluster using Rancher on 5 different CentOS nodes (let's say node1, node2, ..., node5). For our CI run, we need to clean up stale docker images before each run. I created a script that runs on node1, and password-less ssh is enabled from node1 to rest of the nodes. The relevant section of the script looks something like below:
#!/bin/bash
helm ls --short --all | xargs -L1 helm delete --purge
echo "Deleting old data and docker images from Rancher host node."
rm -rf /var/lib/hadoop/* /opt/ci/*
docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f
hosts=(node2 node3 node4 node5)
for host in ${hosts[*]}
do
echo "Deleting old data and docker images from ${host}"
ssh root@${host} docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f
ssh root@${host} rm -rf /var/lib/hadoop/* /opt/ci/*
done
echo "All deletions are complete! Proceeding with installation."
sleep 2m
Problem is, while the docker rmi
command inside the for loop runs for all other 4 nodes, I get the error Error: No such image: <image-id>
for each of the images. But if I execute same command on that node, it succeeds. I'm not sure what's the issue here. Any help is appreciated.
linux bash docker

linux bash docker

edited Jan 3 at 9:58
Bitswazsky
asked Jan 3 at 9:43


BitswazskyBitswazsky
7411920
7411920
Add quotes to ssh command. Thedocker images
is running on the remote machine but the rest the command beginninggrep localhost
is running on the local machine where you executed the script.
– Zaboj Campula
Jan 3 at 9:57
I think that might not be an issue. Actually I executed a partial command from node1 against node3,ssh root@node3 docker images | grep localhost | awk '{print $3}'
and it listed down all image-ids present in node3
– Bitswazsky
Jan 3 at 10:04
2
sure it prints images in node 3. Becausedocker images
is executes at node 3. Then the output is transferred to node1 and grep and awk just filter the text data at node1. But when you try delete an image then you need to do it at node3. Tryssh root@${host} "docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f"
– Zaboj Campula
Jan 3 at 10:10
@Zaboj Thanks a lot. That solved the issue.
– Bitswazsky
Jan 3 at 10:16
1
As an aside,awk '/localhost/ { print $3 }'
gets rid of the useless use ofgrep
.
– tripleee
Jan 3 at 10:20
add a comment |
Add quotes to ssh command. Thedocker images
is running on the remote machine but the rest the command beginninggrep localhost
is running on the local machine where you executed the script.
– Zaboj Campula
Jan 3 at 9:57
I think that might not be an issue. Actually I executed a partial command from node1 against node3,ssh root@node3 docker images | grep localhost | awk '{print $3}'
and it listed down all image-ids present in node3
– Bitswazsky
Jan 3 at 10:04
2
sure it prints images in node 3. Becausedocker images
is executes at node 3. Then the output is transferred to node1 and grep and awk just filter the text data at node1. But when you try delete an image then you need to do it at node3. Tryssh root@${host} "docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f"
– Zaboj Campula
Jan 3 at 10:10
@Zaboj Thanks a lot. That solved the issue.
– Bitswazsky
Jan 3 at 10:16
1
As an aside,awk '/localhost/ { print $3 }'
gets rid of the useless use ofgrep
.
– tripleee
Jan 3 at 10:20
Add quotes to ssh command. The
docker images
is running on the remote machine but the rest the command beginning grep localhost
is running on the local machine where you executed the script.– Zaboj Campula
Jan 3 at 9:57
Add quotes to ssh command. The
docker images
is running on the remote machine but the rest the command beginning grep localhost
is running on the local machine where you executed the script.– Zaboj Campula
Jan 3 at 9:57
I think that might not be an issue. Actually I executed a partial command from node1 against node3,
ssh root@node3 docker images | grep localhost | awk '{print $3}'
and it listed down all image-ids present in node3– Bitswazsky
Jan 3 at 10:04
I think that might not be an issue. Actually I executed a partial command from node1 against node3,
ssh root@node3 docker images | grep localhost | awk '{print $3}'
and it listed down all image-ids present in node3– Bitswazsky
Jan 3 at 10:04
2
2
sure it prints images in node 3. Because
docker images
is executes at node 3. Then the output is transferred to node1 and grep and awk just filter the text data at node1. But when you try delete an image then you need to do it at node3. Try ssh root@${host} "docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f"
– Zaboj Campula
Jan 3 at 10:10
sure it prints images in node 3. Because
docker images
is executes at node 3. Then the output is transferred to node1 and grep and awk just filter the text data at node1. But when you try delete an image then you need to do it at node3. Try ssh root@${host} "docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f"
– Zaboj Campula
Jan 3 at 10:10
@Zaboj Thanks a lot. That solved the issue.
– Bitswazsky
Jan 3 at 10:16
@Zaboj Thanks a lot. That solved the issue.
– Bitswazsky
Jan 3 at 10:16
1
1
As an aside,
awk '/localhost/ { print $3 }'
gets rid of the useless use of grep
.– tripleee
Jan 3 at 10:20
As an aside,
awk '/localhost/ { print $3 }'
gets rid of the useless use of grep
.– tripleee
Jan 3 at 10:20
add a comment |
1 Answer
1
active
oldest
votes
The problem is that the only the first command in the ssh pipe is executed remotely:
ssh root@${host} docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f
Shell understand that it is
ssh ssh-arguments | grep grep-arguments | awk awk-arguments | xarg xarg-arguments
And the result is that the only docker images
is executed remotely. Then the output from the remote docker images
is transferred to the local machine where it is filtered by grep
and awk
and then docker rmi
is executed on local machine.
It is necessary to add quotes to inform shell that everything at command line is a ssh argument:
ssh root@${host} "docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f"
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019705%2fissue-in-removing-docker-images-remotely-on-centos%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem is that the only the first command in the ssh pipe is executed remotely:
ssh root@${host} docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f
Shell understand that it is
ssh ssh-arguments | grep grep-arguments | awk awk-arguments | xarg xarg-arguments
And the result is that the only docker images
is executed remotely. Then the output from the remote docker images
is transferred to the local machine where it is filtered by grep
and awk
and then docker rmi
is executed on local machine.
It is necessary to add quotes to inform shell that everything at command line is a ssh argument:
ssh root@${host} "docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f"
add a comment |
The problem is that the only the first command in the ssh pipe is executed remotely:
ssh root@${host} docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f
Shell understand that it is
ssh ssh-arguments | grep grep-arguments | awk awk-arguments | xarg xarg-arguments
And the result is that the only docker images
is executed remotely. Then the output from the remote docker images
is transferred to the local machine where it is filtered by grep
and awk
and then docker rmi
is executed on local machine.
It is necessary to add quotes to inform shell that everything at command line is a ssh argument:
ssh root@${host} "docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f"
add a comment |
The problem is that the only the first command in the ssh pipe is executed remotely:
ssh root@${host} docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f
Shell understand that it is
ssh ssh-arguments | grep grep-arguments | awk awk-arguments | xarg xarg-arguments
And the result is that the only docker images
is executed remotely. Then the output from the remote docker images
is transferred to the local machine where it is filtered by grep
and awk
and then docker rmi
is executed on local machine.
It is necessary to add quotes to inform shell that everything at command line is a ssh argument:
ssh root@${host} "docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f"
The problem is that the only the first command in the ssh pipe is executed remotely:
ssh root@${host} docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f
Shell understand that it is
ssh ssh-arguments | grep grep-arguments | awk awk-arguments | xarg xarg-arguments
And the result is that the only docker images
is executed remotely. Then the output from the remote docker images
is transferred to the local machine where it is filtered by grep
and awk
and then docker rmi
is executed on local machine.
It is necessary to add quotes to inform shell that everything at command line is a ssh argument:
ssh root@${host} "docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f"
answered Jan 3 at 10:36


Zaboj CampulaZaboj Campula
2,00021827
2,00021827
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019705%2fissue-in-removing-docker-images-remotely-on-centos%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Add quotes to ssh command. The
docker images
is running on the remote machine but the rest the command beginninggrep localhost
is running on the local machine where you executed the script.– Zaboj Campula
Jan 3 at 9:57
I think that might not be an issue. Actually I executed a partial command from node1 against node3,
ssh root@node3 docker images | grep localhost | awk '{print $3}'
and it listed down all image-ids present in node3– Bitswazsky
Jan 3 at 10:04
2
sure it prints images in node 3. Because
docker images
is executes at node 3. Then the output is transferred to node1 and grep and awk just filter the text data at node1. But when you try delete an image then you need to do it at node3. Tryssh root@${host} "docker images | grep localhost | awk '{print $3}' | xargs docker rmi -f"
– Zaboj Campula
Jan 3 at 10:10
@Zaboj Thanks a lot. That solved the issue.
– Bitswazsky
Jan 3 at 10:16
1
As an aside,
awk '/localhost/ { print $3 }'
gets rid of the useless use ofgrep
.– tripleee
Jan 3 at 10:20