How do I get the IP address of an LXC container for automation?How do I get the IP address of an LXC...
What are the rules for concealing thieves' tools (or items in general)?
Nested Dynamic SOQL Query
Error in master's thesis, I do not know what to do
Why doesn't the fusion process of the sun speed up?
CLI: Get information Ubuntu releases
Hot air balloons as primitive bombers
Why is participating in the European Parliamentary elections used as a threat?
How to balance a monster modification (zombie)?
Is VPN a layer 3 concept?
Can a university suspend a student even when he has left university?
Air travel with refrigerated insulin
What kind of footwear is suitable for walking in micro gravity environment?
Is there any common country to visit for uk and schengen visa?
Would this string work as string?
Would mining huge amounts of resources on the Moon change its orbit?
How do researchers send unsolicited emails asking for feedback on their works?
What is the difference between something being completely legal and being completely decriminalized?
Do I need to convey a moral for each of my blog post?
Why I don't get the wanted width of tcbox?
How do you justify more code being written by following clean code practices?
Pre-Employment Background Check With Consent For Future Checks
Single word to change groups
PTIJ: At the Passover Seder, is one allowed to speak more than once during Maggid?
Could any one tell what PN is this Chip? Thanks~
How do I get the IP address of an LXC container for automation?
How do I get the IP address of an LXC container?Public IP Address for LXC containerGetting data from the outside into my linux container?LXC USB Device PassthroughProblem setting up a user-space LXC containerWhere to configure lxd containers?Cannot launch lxc containers get 'error: a remote name must be provided'How do I get ipv4/inet working in a arm lxc container running on intel host?guestmount inside a lxd container gives an “Operation not permitted” errorLXD container set static ipDisable IPv6 from boot inside LXD/LXC container
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
4311622
4311622
add a comment |
add a comment |
6 Answers
6
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 |
pylxd is the official python API client interface developed, supported, and endorsed by the LXD project.
Installation instructions here
$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
>>> from pylxd import Client
>>> client = Client()
>>> for p in client.containers.all(): print(p.name, p.state().network['eth0']['addresses'][0]['address'])
...
stretch-cc 10.76.67.242
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
6 Answers
6
active
oldest
votes
6 Answers
6
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
86621631
86621631
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
51727
51727
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 |
pylxd is the official python API client interface developed, supported, and endorsed by the LXD project.
Installation instructions here
$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
>>> from pylxd import Client
>>> client = Client()
>>> for p in client.containers.all(): print(p.name, p.state().network['eth0']['addresses'][0]['address'])
...
stretch-cc 10.76.67.242
add a comment |
pylxd is the official python API client interface developed, supported, and endorsed by the LXD project.
Installation instructions here
$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
>>> from pylxd import Client
>>> client = Client()
>>> for p in client.containers.all(): print(p.name, p.state().network['eth0']['addresses'][0]['address'])
...
stretch-cc 10.76.67.242
add a comment |
pylxd is the official python API client interface developed, supported, and endorsed by the LXD project.
Installation instructions here
$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
>>> from pylxd import Client
>>> client = Client()
>>> for p in client.containers.all(): print(p.name, p.state().network['eth0']['addresses'][0]['address'])
...
stretch-cc 10.76.67.242
pylxd is the official python API client interface developed, supported, and endorsed by the LXD project.
Installation instructions here
$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
>>> from pylxd import Client
>>> client = Client()
>>> for p in client.containers.all(): print(p.name, p.state().network['eth0']['addresses'][0]['address'])
...
stretch-cc 10.76.67.242
answered 9 mins ago
Craig HicksCraig Hicks
24719
24719
add a comment |
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