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

Exit shell with shortcut (not typing exit) that closes session properly

Homology of the fiber

Why is "la Gestapo" feminine?

If I cast the Enlarge/Reduce spell on an arrow, what weapon could it count as?

Does fire aspect on a sword, destroy mob drops?

Can "few" be used as a subject? If so, what is the rule?

Does convergence of polynomials imply that of its coefficients?

PTIJ: At the Passover Seder, is one allowed to speak more than once during Maggid?

Symbolism of 18 Journeyers

Determine voltage drop over 10G resistors with cheap multimeter

Do I need an EFI partition for each 18.04 ubuntu I have on my HD?

UK Tourist Visa- Enquiry

Air travel with refrigerated insulin

Writing in a Christian voice

Help with identifying unique aircraft over NE Pennsylvania

is this saw blade faulty?

Can a university suspend a student even when he has left university?

Why does Surtur say that Thor is Asgard's doom?

Is VPN a layer 3 concept?

Why is this tree refusing to shed its dead leaves?

Did Nintendo change its mind about 68000 SNES?

How are passwords stolen from companies if they only store hashes?

PTIJ: Which Dr. Seuss books should one obtain?

How can an organ that provides biological immortality be unable to regenerate?



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













3















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.










share|improve this question


























    3















    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.










    share|improve this question
























      3












      3








      3


      1






      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.










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 1 '17 at 14:36









      jgomo3jgomo3

      4311622




      4311622




















          6 Answers
          6






          active

          oldest

          votes


















          2














          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.






          share|improve this answer






























            2














            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.






            share|improve this answer




















            • 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



















            1














            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.






            share|improve this answer
































              0














              Probably a bit ugly but:



              lxc-info -n my-container | grep IP: | tr -d ' ' | cut -f2 -d:


              will get you just the IP address






              share|improve this answer























              • 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


















              0














              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





              share|improve this answer






























                -1














                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.






                share|improve this answer






















                  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
                  );



                  );













                  draft saved

                  draft discarded


















                  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









                  2














                  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.






                  share|improve this answer



























                    2














                    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.






                    share|improve this answer

























                      2












                      2








                      2







                      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.






                      share|improve this answer













                      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.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jun 13 '17 at 21:27









                      Jonathan Y.Jonathan Y.

                      504928




                      504928























                          2














                          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.






                          share|improve this answer




















                          • 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
















                          2














                          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.






                          share|improve this answer




















                          • 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














                          2












                          2








                          2







                          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.






                          share|improve this answer















                          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.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Feb 2 '18 at 2:13









                          muru

                          1




                          1










                          answered Feb 1 '18 at 23:55









                          NeilNeil

                          211




                          211







                          • 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













                          • 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








                          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












                          1














                          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.






                          share|improve this answer





























                            1














                            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.






                            share|improve this answer



























                              1












                              1








                              1







                              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.






                              share|improve this answer















                              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.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jan 29 at 10:39

























                              answered Jul 14 '18 at 1:23









                              anatoly techtonikanatoly techtonik

                              86621631




                              86621631





















                                  0














                                  Probably a bit ugly but:



                                  lxc-info -n my-container | grep IP: | tr -d ' ' | cut -f2 -d:


                                  will get you just the IP address






                                  share|improve this answer























                                  • 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















                                  0














                                  Probably a bit ugly but:



                                  lxc-info -n my-container | grep IP: | tr -d ' ' | cut -f2 -d:


                                  will get you just the IP address






                                  share|improve this answer























                                  • 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













                                  0












                                  0








                                  0







                                  Probably a bit ugly but:



                                  lxc-info -n my-container | grep IP: | tr -d ' ' | cut -f2 -d:


                                  will get you just the IP address






                                  share|improve this answer













                                  Probably a bit ugly but:



                                  lxc-info -n my-container | grep IP: | tr -d ' ' | cut -f2 -d:


                                  will get you just the IP address







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  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 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

















                                  • 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
















                                  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











                                  0














                                  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





                                  share|improve this answer



























                                    0














                                    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





                                    share|improve this answer

























                                      0












                                      0








                                      0







                                      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





                                      share|improve this answer













                                      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






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered 28 mins ago









                                      Craig HicksCraig Hicks

                                      24719




                                      24719





















                                          -1














                                          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.






                                          share|improve this answer



























                                            -1














                                            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.






                                            share|improve this answer

























                                              -1












                                              -1








                                              -1







                                              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.






                                              share|improve this answer













                                              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.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Jan 17 '18 at 17:56









                                              G. FiedlerG. Fiedler

                                              992




                                              992



























                                                  draft saved

                                                  draft discarded
















































                                                  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.




                                                  draft saved


                                                  draft discarded














                                                  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





















































                                                  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







                                                  Popular posts from this blog

                                                  Möglingen Índice Localización Historia Demografía Referencias Enlaces externos Menú de navegación48°53′18″N 9°07′45″E / 48.888333333333, 9.129166666666748°53′18″N 9°07′45″E / 48.888333333333, 9.1291666666667Sitio web oficial Mapa de Möglingen«Gemeinden in Deutschland nach Fläche, Bevölkerung und Postleitzahl am 30.09.2016»Möglingen

                                                  Virtualbox - Configuration error: Querying “UUID” failed (VERR_CFGM_VALUE_NOT_FOUND)“VERR_SUPLIB_WORLD_WRITABLE” error when trying to installing OS in virtualboxVirtual Box Kernel errorFailed to open a seesion for the virtual machineFailed to open a session for the virtual machineUbuntu 14.04 LTS Virtualbox errorcan't use VM VirtualBoxusing virtualboxI can't run Linux-64 Bit on VirtualBoxUnable to insert the virtual optical disk (VBoxguestaddition) in virtual machine for ubuntu server in win 10VirtuaBox in Ubuntu 18.04 Issues with Win10.ISO Installation

                                                  Torre de la Isleta Índice Véase también Referencias Bibliografía Enlaces externos Menú de navegación38°25′58″N 0°23′02″O / 38.43277778, -0.3838888938°25′58″N 0°23′02″O / 38.43277778, -0.38388889Torre de la Illeta de l’Horta o Torre Saleta. Base de datos de bienes inmuebles. Patrimonio Cultural. Secretaría de Estado de CulturaFicha BIC Torre de la Illeta de l’Horta. Dirección General de Patrimonio Cultural. Generalitat ValencianaLugares de interés. Ayuntamiento del CampelloTorre de la Isleta en CastillosNet.org