Is there a way to add a hostname to an EXISTING docker container?










1














I have some containers that communicate via their IP from the network docker.



I can use the option -h or --hostname when running a new container but I want to set the hostname for existing container.



Is it possible?










share|improve this question




























    1














    I have some containers that communicate via their IP from the network docker.



    I can use the option -h or --hostname when running a new container but I want to set the hostname for existing container.



    Is it possible?










    share|improve this question


























      1












      1








      1


      2





      I have some containers that communicate via their IP from the network docker.



      I can use the option -h or --hostname when running a new container but I want to set the hostname for existing container.



      Is it possible?










      share|improve this question















      I have some containers that communicate via their IP from the network docker.



      I can use the option -h or --hostname when running a new container but I want to set the hostname for existing container.



      Is it possible?







      docker docker-machine






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 '18 at 2:41









      Sergey Brunov

      9,81843065




      9,81843065










      asked Nov 9 '16 at 8:56









      Youssouf Maiga

      8851929




      8851929






















          3 Answers
          3






          active

          oldest

          votes


















          2














          One way is to create network and add different container in this network.
          When adding container in the network, you can use the --alias option of docker network. Like this:




          • Create a network:



            docker network create <my-network-name> 



          • Add containers in the network:



            docker network connect --alias <hostname-container-1> <my-network-name> <container-1>
            docker network connect --alias <hostname-container-2> <my-network-name> <container-2>
            docker network connect --alias <hostname-container-3> <my-network-name> <container-3>


          • Enjoy.


          So each container can see other container by the alias (the alias is used as hostname).






          share|improve this answer






























            0














            Generally, you would need to stop/restart a container, in order to run it again with -h (--hostname) (unless you used --net=host)



            If you cannot stop the container, you can try and (in an attached bash session) edit its /etc/hostname.






            share|improve this answer






























              0














              The hostname is immutable once the container is created (although technically you can modify /etc/hostname).



              As suggested in another answer, you cannot change the hostname by stopping or restarting the container. There are not Docker engine client parameters for the start command that affect hostname. That wouldn't make sense anyway as starting a container simply launches the ENTRYPOINT process in a container filesystem that has already been created (i.e. /etc/hostname has already been written).



              It is possible to synchronize the container hostname with the host by using the --uts=host parameter when the container is created. This shares the UTS namespace. I would not recommend --net=host unless you also want to share the host network devices (i.e. bypass the Docker bridge).






              share|improve this answer




















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



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40503002%2fis-there-a-way-to-add-a-hostname-to-an-existing-docker-container%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                2














                One way is to create network and add different container in this network.
                When adding container in the network, you can use the --alias option of docker network. Like this:




                • Create a network:



                  docker network create <my-network-name> 



                • Add containers in the network:



                  docker network connect --alias <hostname-container-1> <my-network-name> <container-1>
                  docker network connect --alias <hostname-container-2> <my-network-name> <container-2>
                  docker network connect --alias <hostname-container-3> <my-network-name> <container-3>


                • Enjoy.


                So each container can see other container by the alias (the alias is used as hostname).






                share|improve this answer



























                  2














                  One way is to create network and add different container in this network.
                  When adding container in the network, you can use the --alias option of docker network. Like this:




                  • Create a network:



                    docker network create <my-network-name> 



                  • Add containers in the network:



                    docker network connect --alias <hostname-container-1> <my-network-name> <container-1>
                    docker network connect --alias <hostname-container-2> <my-network-name> <container-2>
                    docker network connect --alias <hostname-container-3> <my-network-name> <container-3>


                  • Enjoy.


                  So each container can see other container by the alias (the alias is used as hostname).






                  share|improve this answer

























                    2












                    2








                    2






                    One way is to create network and add different container in this network.
                    When adding container in the network, you can use the --alias option of docker network. Like this:




                    • Create a network:



                      docker network create <my-network-name> 



                    • Add containers in the network:



                      docker network connect --alias <hostname-container-1> <my-network-name> <container-1>
                      docker network connect --alias <hostname-container-2> <my-network-name> <container-2>
                      docker network connect --alias <hostname-container-3> <my-network-name> <container-3>


                    • Enjoy.


                    So each container can see other container by the alias (the alias is used as hostname).






                    share|improve this answer














                    One way is to create network and add different container in this network.
                    When adding container in the network, you can use the --alias option of docker network. Like this:




                    • Create a network:



                      docker network create <my-network-name> 



                    • Add containers in the network:



                      docker network connect --alias <hostname-container-1> <my-network-name> <container-1>
                      docker network connect --alias <hostname-container-2> <my-network-name> <container-2>
                      docker network connect --alias <hostname-container-3> <my-network-name> <container-3>


                    • Enjoy.


                    So each container can see other container by the alias (the alias is used as hostname).







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 12 '18 at 16:04









                    Sergey Brunov

                    9,81843065




                    9,81843065










                    answered Dec 23 '16 at 8:47









                    Youssouf Maiga

                    8851929




                    8851929























                        0














                        Generally, you would need to stop/restart a container, in order to run it again with -h (--hostname) (unless you used --net=host)



                        If you cannot stop the container, you can try and (in an attached bash session) edit its /etc/hostname.






                        share|improve this answer



























                          0














                          Generally, you would need to stop/restart a container, in order to run it again with -h (--hostname) (unless you used --net=host)



                          If you cannot stop the container, you can try and (in an attached bash session) edit its /etc/hostname.






                          share|improve this answer

























                            0












                            0








                            0






                            Generally, you would need to stop/restart a container, in order to run it again with -h (--hostname) (unless you used --net=host)



                            If you cannot stop the container, you can try and (in an attached bash session) edit its /etc/hostname.






                            share|improve this answer














                            Generally, you would need to stop/restart a container, in order to run it again with -h (--hostname) (unless you used --net=host)



                            If you cannot stop the container, you can try and (in an attached bash session) edit its /etc/hostname.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Apr 13 '17 at 12:13









                            Community

                            11




                            11










                            answered Nov 9 '16 at 9:31









                            VonC

                            832k28926163161




                            832k28926163161





















                                0














                                The hostname is immutable once the container is created (although technically you can modify /etc/hostname).



                                As suggested in another answer, you cannot change the hostname by stopping or restarting the container. There are not Docker engine client parameters for the start command that affect hostname. That wouldn't make sense anyway as starting a container simply launches the ENTRYPOINT process in a container filesystem that has already been created (i.e. /etc/hostname has already been written).



                                It is possible to synchronize the container hostname with the host by using the --uts=host parameter when the container is created. This shares the UTS namespace. I would not recommend --net=host unless you also want to share the host network devices (i.e. bypass the Docker bridge).






                                share|improve this answer

























                                  0














                                  The hostname is immutable once the container is created (although technically you can modify /etc/hostname).



                                  As suggested in another answer, you cannot change the hostname by stopping or restarting the container. There are not Docker engine client parameters for the start command that affect hostname. That wouldn't make sense anyway as starting a container simply launches the ENTRYPOINT process in a container filesystem that has already been created (i.e. /etc/hostname has already been written).



                                  It is possible to synchronize the container hostname with the host by using the --uts=host parameter when the container is created. This shares the UTS namespace. I would not recommend --net=host unless you also want to share the host network devices (i.e. bypass the Docker bridge).






                                  share|improve this answer























                                    0












                                    0








                                    0






                                    The hostname is immutable once the container is created (although technically you can modify /etc/hostname).



                                    As suggested in another answer, you cannot change the hostname by stopping or restarting the container. There are not Docker engine client parameters for the start command that affect hostname. That wouldn't make sense anyway as starting a container simply launches the ENTRYPOINT process in a container filesystem that has already been created (i.e. /etc/hostname has already been written).



                                    It is possible to synchronize the container hostname with the host by using the --uts=host parameter when the container is created. This shares the UTS namespace. I would not recommend --net=host unless you also want to share the host network devices (i.e. bypass the Docker bridge).






                                    share|improve this answer












                                    The hostname is immutable once the container is created (although technically you can modify /etc/hostname).



                                    As suggested in another answer, you cannot change the hostname by stopping or restarting the container. There are not Docker engine client parameters for the start command that affect hostname. That wouldn't make sense anyway as starting a container simply launches the ENTRYPOINT process in a container filesystem that has already been created (i.e. /etc/hostname has already been written).



                                    It is possible to synchronize the container hostname with the host by using the --uts=host parameter when the container is created. This shares the UTS namespace. I would not recommend --net=host unless you also want to share the host network devices (i.e. bypass the Docker bridge).







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 9 '16 at 16:23









                                    James Moser

                                    23615




                                    23615



























                                        draft saved

                                        draft discarded
















































                                        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.





                                        Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                        Please pay close attention to the following guidance:


                                        • 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%2fstackoverflow.com%2fquestions%2f40503002%2fis-there-a-way-to-add-a-hostname-to-an-existing-docker-container%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

                                        How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                                        Syphilis

                                        Darth Vader #20