How do I get the IP address of an LXC container for automation?
How can I get the IP address of an LXC container in a format I can use in scripting?
Right now, the command lxc info <container>
report that information, but in a human readable format, with a lot of information.
I would like to ONLY to GET the IP address given a container name.
Note: I HAVE to duplicate this question because Linux Containers have changed a lot.
Installing lxd and using unprivileged containers is the default way to go this days (2017) and I think the solutions posted on the original question are do not resolve the issue in this case.
In any case, I installed the package lxc1 to get access to the command lxc-info
, but that command doesn't recognize any of my unprivileged containers.
lxc lxd
add a comment |
How can I get the IP address of an LXC container in a format I can use in scripting?
Right now, the command lxc info <container>
report that information, but in a human readable format, with a lot of information.
I would like to ONLY to GET the IP address given a container name.
Note: I HAVE to duplicate this question because Linux Containers have changed a lot.
Installing lxd and using unprivileged containers is the default way to go this days (2017) and I think the solutions posted on the original question are do not resolve the issue in this case.
In any case, I installed the package lxc1 to get access to the command lxc-info
, but that command doesn't recognize any of my unprivileged containers.
lxc lxd
add a comment |
How can I get the IP address of an LXC container in a format I can use in scripting?
Right now, the command lxc info <container>
report that information, but in a human readable format, with a lot of information.
I would like to ONLY to GET the IP address given a container name.
Note: I HAVE to duplicate this question because Linux Containers have changed a lot.
Installing lxd and using unprivileged containers is the default way to go this days (2017) and I think the solutions posted on the original question are do not resolve the issue in this case.
In any case, I installed the package lxc1 to get access to the command lxc-info
, but that command doesn't recognize any of my unprivileged containers.
lxc lxd
How can I get the IP address of an LXC container in a format I can use in scripting?
Right now, the command lxc info <container>
report that information, but in a human readable format, with a lot of information.
I would like to ONLY to GET the IP address given a container name.
Note: I HAVE to duplicate this question because Linux Containers have changed a lot.
Installing lxd and using unprivileged containers is the default way to go this days (2017) and I think the solutions posted on the original question are do not resolve the issue in this case.
In any case, I installed the package lxc1 to get access to the command lxc-info
, but that command doesn't recognize any of my unprivileged containers.
lxc lxd
lxc lxd
asked Jun 1 '17 at 14:36
jgomo3jgomo3
4261622
4261622
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
A native solution (which isn't any prettier than @siloko's answer) would be
lxc list "<name>" -c 4 | awk '!/IPV4/{ if ( $2 != "" ) print $2}'
There are alternatives to awk
, but that's tangential to the question.
add a comment |
lxc list | grep nameofthecontainer | egrep -o "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
This is what I am using, I pass the container name in as a variable.
2
thegrep
command is unneded, you can put directlylxc list container_name | egrep -o "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
with the same result
– Yonsy Solis
Feb 20 '18 at 15:45
add a comment |
So far this is the easiest way:
lxc list -c4 --format csv <container> | cut -d' ' -f1
But maybe it will be possible without cut
.
EDIT: Uncut bash:
a=( $(lxc list -c4 --format csv u1) ) ip4=$a[1] echo $ip4
Hint from @monstermunchkin from the above issue.
add a comment |
Probably a bit ugly but:
lxc-info -n my-container | grep IP: | tr -d ' ' | cut -f2 -d:
will get you just the IP address
Thank you. It would be a solution in the near time. BTW, the idea is to use the commandlxc info
, notlxc-info
as they are different how I explained.
– jgomo3
Jun 1 '17 at 14:58
barelxc
is not available on my system (Ubuntu 16.04), sorry.
– siloko
Jun 2 '17 at 6:55
add a comment |
lxc-info --name container --ips --no-humanize
prints the container IP addresses.
The returned value is a list because a container can have more than one address.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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%2faskubuntu.com%2fquestions%2f921110%2fhow-do-i-get-the-ip-address-of-an-lxc-container-for-automation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
A native solution (which isn't any prettier than @siloko's answer) would be
lxc list "<name>" -c 4 | awk '!/IPV4/{ if ( $2 != "" ) print $2}'
There are alternatives to awk
, but that's tangential to the question.
add a comment |
A native solution (which isn't any prettier than @siloko's answer) would be
lxc list "<name>" -c 4 | awk '!/IPV4/{ if ( $2 != "" ) print $2}'
There are alternatives to awk
, but that's tangential to the question.
add a comment |
A native solution (which isn't any prettier than @siloko's answer) would be
lxc list "<name>" -c 4 | awk '!/IPV4/{ if ( $2 != "" ) print $2}'
There are alternatives to awk
, but that's tangential to the question.
A native solution (which isn't any prettier than @siloko's answer) would be
lxc list "<name>" -c 4 | awk '!/IPV4/{ if ( $2 != "" ) print $2}'
There are alternatives to awk
, but that's tangential to the question.
answered Jun 13 '17 at 21:27
Jonathan Y.Jonathan Y.
504928
504928
add a comment |
add a comment |
lxc list | grep nameofthecontainer | egrep -o "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
This is what I am using, I pass the container name in as a variable.
2
thegrep
command is unneded, you can put directlylxc list container_name | egrep -o "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
with the same result
– Yonsy Solis
Feb 20 '18 at 15:45
add a comment |
lxc list | grep nameofthecontainer | egrep -o "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
This is what I am using, I pass the container name in as a variable.
2
thegrep
command is unneded, you can put directlylxc list container_name | egrep -o "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
with the same result
– Yonsy Solis
Feb 20 '18 at 15:45
add a comment |
lxc list | grep nameofthecontainer | egrep -o "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
This is what I am using, I pass the container name in as a variable.
lxc list | grep nameofthecontainer | egrep -o "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
This is what I am using, I pass the container name in as a variable.
edited Feb 2 '18 at 2:13
muru
1
1
answered Feb 1 '18 at 23:55
NeilNeil
211
211
2
thegrep
command is unneded, you can put directlylxc list container_name | egrep -o "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
with the same result
– Yonsy Solis
Feb 20 '18 at 15:45
add a comment |
2
thegrep
command is unneded, you can put directlylxc list container_name | egrep -o "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
with the same result
– Yonsy Solis
Feb 20 '18 at 15:45
2
2
the
grep
command is unneded, you can put directly lxc list container_name | egrep -o "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
with the same result– Yonsy Solis
Feb 20 '18 at 15:45
the
grep
command is unneded, you can put directly lxc list container_name | egrep -o "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
with the same result– Yonsy Solis
Feb 20 '18 at 15:45
add a comment |
So far this is the easiest way:
lxc list -c4 --format csv <container> | cut -d' ' -f1
But maybe it will be possible without cut
.
EDIT: Uncut bash:
a=( $(lxc list -c4 --format csv u1) ) ip4=$a[1] echo $ip4
Hint from @monstermunchkin from the above issue.
add a comment |
So far this is the easiest way:
lxc list -c4 --format csv <container> | cut -d' ' -f1
But maybe it will be possible without cut
.
EDIT: Uncut bash:
a=( $(lxc list -c4 --format csv u1) ) ip4=$a[1] echo $ip4
Hint from @monstermunchkin from the above issue.
add a comment |
So far this is the easiest way:
lxc list -c4 --format csv <container> | cut -d' ' -f1
But maybe it will be possible without cut
.
EDIT: Uncut bash:
a=( $(lxc list -c4 --format csv u1) ) ip4=$a[1] echo $ip4
Hint from @monstermunchkin from the above issue.
So far this is the easiest way:
lxc list -c4 --format csv <container> | cut -d' ' -f1
But maybe it will be possible without cut
.
EDIT: Uncut bash:
a=( $(lxc list -c4 --format csv u1) ) ip4=$a[1] echo $ip4
Hint from @monstermunchkin from the above issue.
edited Jan 29 at 10:39
answered Jul 14 '18 at 1:23
anatoly techtonikanatoly techtonik
84121431
84121431
add a comment |
add a comment |
Probably a bit ugly but:
lxc-info -n my-container | grep IP: | tr -d ' ' | cut -f2 -d:
will get you just the IP address
Thank you. It would be a solution in the near time. BTW, the idea is to use the commandlxc info
, notlxc-info
as they are different how I explained.
– jgomo3
Jun 1 '17 at 14:58
barelxc
is not available on my system (Ubuntu 16.04), sorry.
– siloko
Jun 2 '17 at 6:55
add a comment |
Probably a bit ugly but:
lxc-info -n my-container | grep IP: | tr -d ' ' | cut -f2 -d:
will get you just the IP address
Thank you. It would be a solution in the near time. BTW, the idea is to use the commandlxc info
, notlxc-info
as they are different how I explained.
– jgomo3
Jun 1 '17 at 14:58
barelxc
is not available on my system (Ubuntu 16.04), sorry.
– siloko
Jun 2 '17 at 6:55
add a comment |
Probably a bit ugly but:
lxc-info -n my-container | grep IP: | tr -d ' ' | cut -f2 -d:
will get you just the IP address
Probably a bit ugly but:
lxc-info -n my-container | grep IP: | tr -d ' ' | cut -f2 -d:
will get you just the IP address
answered Jun 1 '17 at 14:54
silokosiloko
50727
50727
Thank you. It would be a solution in the near time. BTW, the idea is to use the commandlxc info
, notlxc-info
as they are different how I explained.
– jgomo3
Jun 1 '17 at 14:58
barelxc
is not available on my system (Ubuntu 16.04), sorry.
– siloko
Jun 2 '17 at 6:55
add a comment |
Thank you. It would be a solution in the near time. BTW, the idea is to use the commandlxc info
, notlxc-info
as they are different how I explained.
– jgomo3
Jun 1 '17 at 14:58
barelxc
is not available on my system (Ubuntu 16.04), sorry.
– siloko
Jun 2 '17 at 6:55
Thank you. It would be a solution in the near time. BTW, the idea is to use the command
lxc info
, not lxc-info
as they are different how I explained.– jgomo3
Jun 1 '17 at 14:58
Thank you. It would be a solution in the near time. BTW, the idea is to use the command
lxc info
, not lxc-info
as they are different how I explained.– jgomo3
Jun 1 '17 at 14:58
bare
lxc
is not available on my system (Ubuntu 16.04), sorry.– siloko
Jun 2 '17 at 6:55
bare
lxc
is not available on my system (Ubuntu 16.04), sorry.– siloko
Jun 2 '17 at 6:55
add a comment |
lxc-info --name container --ips --no-humanize
prints the container IP addresses.
The returned value is a list because a container can have more than one address.
add a comment |
lxc-info --name container --ips --no-humanize
prints the container IP addresses.
The returned value is a list because a container can have more than one address.
add a comment |
lxc-info --name container --ips --no-humanize
prints the container IP addresses.
The returned value is a list because a container can have more than one address.
lxc-info --name container --ips --no-humanize
prints the container IP addresses.
The returned value is a list because a container can have more than one address.
answered Jan 17 '18 at 17:56
G. FiedlerG. Fiedler
992
992
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f921110%2fhow-do-i-get-the-ip-address-of-an-lxc-container-for-automation%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