Mysql connect host change every time in the docker container,why?











up vote
0
down vote

favorite
1












In the docker container.I try to login the host mysql server. First the host ip is changed,so confused for me.But second login success. Anyone can explain this strange happening?



I login ip is 192.168.100.164,but the error info shows ip 172.18.0.4,which is the container localhost.



enter image description here



More info:



root@b67c39311dbb:~/project# netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.18.0.1 0.0.0.0 UG 0 0 0 eth0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
root@b67c39311dbb:~/project# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.0.4 netmask 255.255.0.0 broadcast 172.18.255.255
ether 02:42:ac:12:00:04 txqueuelen 0 (Ethernet)
RX packets 2099 bytes 2414555 (2.4 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1752 bytes 132863 (132.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 35 bytes 3216 (3.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 35 bytes 3216 (3.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0









share|improve this question
























  • why do you need to use the dynamic IPs assigned by docker daemon if you can map the container 3306 port to your 127.0.0.1 and always use 127.0.0.1?
    – Alexey
    Oct 25 at 10:27










  • No, you misunderstand what I said before. 192.168.100.164 is my host machine ip , and in the container which running on host machine, the command: ping 192.168.100.164 work well, but mysql -u develop -h 192.168.100.164 -p raise error: ERROR(1045)...Access denied for user 'develop'@'172.18.0.4' sometimes. The ip 172.18.0.4 in the error is container ip,not I set.
    – xander-ye
    Nov 6 at 9:19












  • why not trying mysql -u develop -h 127.0.0.1 ?
    – Alexey
    Nov 7 at 7:19










  • HEHE... the mysql server which I want logining is on my host machine,not on the container. you know,I am in the docker container now.
    – xander-ye
    Nov 7 at 8:33















up vote
0
down vote

favorite
1












In the docker container.I try to login the host mysql server. First the host ip is changed,so confused for me.But second login success. Anyone can explain this strange happening?



I login ip is 192.168.100.164,but the error info shows ip 172.18.0.4,which is the container localhost.



enter image description here



More info:



root@b67c39311dbb:~/project# netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.18.0.1 0.0.0.0 UG 0 0 0 eth0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
root@b67c39311dbb:~/project# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.0.4 netmask 255.255.0.0 broadcast 172.18.255.255
ether 02:42:ac:12:00:04 txqueuelen 0 (Ethernet)
RX packets 2099 bytes 2414555 (2.4 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1752 bytes 132863 (132.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 35 bytes 3216 (3.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 35 bytes 3216 (3.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0









share|improve this question
























  • why do you need to use the dynamic IPs assigned by docker daemon if you can map the container 3306 port to your 127.0.0.1 and always use 127.0.0.1?
    – Alexey
    Oct 25 at 10:27










  • No, you misunderstand what I said before. 192.168.100.164 is my host machine ip , and in the container which running on host machine, the command: ping 192.168.100.164 work well, but mysql -u develop -h 192.168.100.164 -p raise error: ERROR(1045)...Access denied for user 'develop'@'172.18.0.4' sometimes. The ip 172.18.0.4 in the error is container ip,not I set.
    – xander-ye
    Nov 6 at 9:19












  • why not trying mysql -u develop -h 127.0.0.1 ?
    – Alexey
    Nov 7 at 7:19










  • HEHE... the mysql server which I want logining is on my host machine,not on the container. you know,I am in the docker container now.
    – xander-ye
    Nov 7 at 8:33













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





In the docker container.I try to login the host mysql server. First the host ip is changed,so confused for me.But second login success. Anyone can explain this strange happening?



I login ip is 192.168.100.164,but the error info shows ip 172.18.0.4,which is the container localhost.



enter image description here



More info:



root@b67c39311dbb:~/project# netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.18.0.1 0.0.0.0 UG 0 0 0 eth0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
root@b67c39311dbb:~/project# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.0.4 netmask 255.255.0.0 broadcast 172.18.255.255
ether 02:42:ac:12:00:04 txqueuelen 0 (Ethernet)
RX packets 2099 bytes 2414555 (2.4 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1752 bytes 132863 (132.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 35 bytes 3216 (3.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 35 bytes 3216 (3.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0









share|improve this question















In the docker container.I try to login the host mysql server. First the host ip is changed,so confused for me.But second login success. Anyone can explain this strange happening?



I login ip is 192.168.100.164,but the error info shows ip 172.18.0.4,which is the container localhost.



enter image description here



More info:



root@b67c39311dbb:~/project# netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.18.0.1 0.0.0.0 UG 0 0 0 eth0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
root@b67c39311dbb:~/project# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.0.4 netmask 255.255.0.0 broadcast 172.18.255.255
ether 02:42:ac:12:00:04 txqueuelen 0 (Ethernet)
RX packets 2099 bytes 2414555 (2.4 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1752 bytes 132863 (132.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 35 bytes 3216 (3.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 35 bytes 3216 (3.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0






mysql docker






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 25 at 9:29

























asked Oct 25 at 8:38









xander-ye

6813




6813












  • why do you need to use the dynamic IPs assigned by docker daemon if you can map the container 3306 port to your 127.0.0.1 and always use 127.0.0.1?
    – Alexey
    Oct 25 at 10:27










  • No, you misunderstand what I said before. 192.168.100.164 is my host machine ip , and in the container which running on host machine, the command: ping 192.168.100.164 work well, but mysql -u develop -h 192.168.100.164 -p raise error: ERROR(1045)...Access denied for user 'develop'@'172.18.0.4' sometimes. The ip 172.18.0.4 in the error is container ip,not I set.
    – xander-ye
    Nov 6 at 9:19












  • why not trying mysql -u develop -h 127.0.0.1 ?
    – Alexey
    Nov 7 at 7:19










  • HEHE... the mysql server which I want logining is on my host machine,not on the container. you know,I am in the docker container now.
    – xander-ye
    Nov 7 at 8:33


















  • why do you need to use the dynamic IPs assigned by docker daemon if you can map the container 3306 port to your 127.0.0.1 and always use 127.0.0.1?
    – Alexey
    Oct 25 at 10:27










  • No, you misunderstand what I said before. 192.168.100.164 is my host machine ip , and in the container which running on host machine, the command: ping 192.168.100.164 work well, but mysql -u develop -h 192.168.100.164 -p raise error: ERROR(1045)...Access denied for user 'develop'@'172.18.0.4' sometimes. The ip 172.18.0.4 in the error is container ip,not I set.
    – xander-ye
    Nov 6 at 9:19












  • why not trying mysql -u develop -h 127.0.0.1 ?
    – Alexey
    Nov 7 at 7:19










  • HEHE... the mysql server which I want logining is on my host machine,not on the container. you know,I am in the docker container now.
    – xander-ye
    Nov 7 at 8:33
















why do you need to use the dynamic IPs assigned by docker daemon if you can map the container 3306 port to your 127.0.0.1 and always use 127.0.0.1?
– Alexey
Oct 25 at 10:27




why do you need to use the dynamic IPs assigned by docker daemon if you can map the container 3306 port to your 127.0.0.1 and always use 127.0.0.1?
– Alexey
Oct 25 at 10:27












No, you misunderstand what I said before. 192.168.100.164 is my host machine ip , and in the container which running on host machine, the command: ping 192.168.100.164 work well, but mysql -u develop -h 192.168.100.164 -p raise error: ERROR(1045)...Access denied for user 'develop'@'172.18.0.4' sometimes. The ip 172.18.0.4 in the error is container ip,not I set.
– xander-ye
Nov 6 at 9:19






No, you misunderstand what I said before. 192.168.100.164 is my host machine ip , and in the container which running on host machine, the command: ping 192.168.100.164 work well, but mysql -u develop -h 192.168.100.164 -p raise error: ERROR(1045)...Access denied for user 'develop'@'172.18.0.4' sometimes. The ip 172.18.0.4 in the error is container ip,not I set.
– xander-ye
Nov 6 at 9:19














why not trying mysql -u develop -h 127.0.0.1 ?
– Alexey
Nov 7 at 7:19




why not trying mysql -u develop -h 127.0.0.1 ?
– Alexey
Nov 7 at 7:19












HEHE... the mysql server which I want logining is on my host machine,not on the container. you know,I am in the docker container now.
– xander-ye
Nov 7 at 8:33




HEHE... the mysql server which I want logining is on my host machine,not on the container. you know,I am in the docker container now.
– xander-ye
Nov 7 at 8:33












3 Answers
3






active

oldest

votes

















up vote
0
down vote













Try adding --add-host="localhost:192.168.100.164" when launching docker run. But this is not a good practice to my mind. You should move your mysql database to another container and create a network between them






share|improve this answer





















  • How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
    – Nico Haase
    Nov 8 at 10:57










  • The connection was working on the first attempt as well. If you see the first attempt error message from mysql, it tells him that the user doesn't have access from the container host, but the connection was ok. Who knows what happened to the access rights to allow connections from 172.18.0.4 or % for develop user between the attempts? What I recommended was running mysql inside another container, not on the host machine. But even if the author wants to do so I suggested mapping host into the container network with fixed ip
    – Alexey
    Nov 8 at 11:02




















up vote
0
down vote













That is true, when we start docker container it is get their own ip for container. You need to map host port with docker container. then, when you try to connect host port it redirect to myssql docker container. Please look at https://docs.docker.com/config/containers/container-networking/






share|improve this answer





















  • How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
    – Nico Haase
    Nov 8 at 10:57


















up vote
0
down vote













I'd suggest you to create a docker bridged network and then create your container using the --add-host as suggested by Alexey.



In a simple script:



DOCKER_NET_NAME='the_docker_network_name'
DOCKER_GATEWAY='172.100.0.1'

docker network create
--driver bridge
--subnet=172.100.0.0/16
--gateway=$DOCKER_GATEWAY
$DOCKER_NET_NAME

docker run -d
--add-host db.onthehost:$DOCKER_GATEWAY
--restart=always
--network=$DOCKER_NET_NAME
--name=magicContainerName
yourImage:latest


EDIT: creating a network will also simplify the communication among containers (if you plan to have it in the future) since you'll be able to use the container names instead of their IP.






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',
    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%2f52984913%2fmysql-connect-host-change-every-time-in-the-docker-container-why%23new-answer', 'question_page');
    }
    );

    Post as a guest
































    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Try adding --add-host="localhost:192.168.100.164" when launching docker run. But this is not a good practice to my mind. You should move your mysql database to another container and create a network between them






    share|improve this answer





















    • How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
      – Nico Haase
      Nov 8 at 10:57










    • The connection was working on the first attempt as well. If you see the first attempt error message from mysql, it tells him that the user doesn't have access from the container host, but the connection was ok. Who knows what happened to the access rights to allow connections from 172.18.0.4 or % for develop user between the attempts? What I recommended was running mysql inside another container, not on the host machine. But even if the author wants to do so I suggested mapping host into the container network with fixed ip
      – Alexey
      Nov 8 at 11:02

















    up vote
    0
    down vote













    Try adding --add-host="localhost:192.168.100.164" when launching docker run. But this is not a good practice to my mind. You should move your mysql database to another container and create a network between them






    share|improve this answer





















    • How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
      – Nico Haase
      Nov 8 at 10:57










    • The connection was working on the first attempt as well. If you see the first attempt error message from mysql, it tells him that the user doesn't have access from the container host, but the connection was ok. Who knows what happened to the access rights to allow connections from 172.18.0.4 or % for develop user between the attempts? What I recommended was running mysql inside another container, not on the host machine. But even if the author wants to do so I suggested mapping host into the container network with fixed ip
      – Alexey
      Nov 8 at 11:02















    up vote
    0
    down vote










    up vote
    0
    down vote









    Try adding --add-host="localhost:192.168.100.164" when launching docker run. But this is not a good practice to my mind. You should move your mysql database to another container and create a network between them






    share|improve this answer












    Try adding --add-host="localhost:192.168.100.164" when launching docker run. But this is not a good practice to my mind. You should move your mysql database to another container and create a network between them







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 8 at 9:23









    Alexey

    1,78742036




    1,78742036












    • How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
      – Nico Haase
      Nov 8 at 10:57










    • The connection was working on the first attempt as well. If you see the first attempt error message from mysql, it tells him that the user doesn't have access from the container host, but the connection was ok. Who knows what happened to the access rights to allow connections from 172.18.0.4 or % for develop user between the attempts? What I recommended was running mysql inside another container, not on the host machine. But even if the author wants to do so I suggested mapping host into the container network with fixed ip
      – Alexey
      Nov 8 at 11:02




















    • How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
      – Nico Haase
      Nov 8 at 10:57










    • The connection was working on the first attempt as well. If you see the first attempt error message from mysql, it tells him that the user doesn't have access from the container host, but the connection was ok. Who knows what happened to the access rights to allow connections from 172.18.0.4 or % for develop user between the attempts? What I recommended was running mysql inside another container, not on the host machine. But even if the author wants to do so I suggested mapping host into the container network with fixed ip
      – Alexey
      Nov 8 at 11:02


















    How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
    – Nico Haase
    Nov 8 at 10:57




    How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
    – Nico Haase
    Nov 8 at 10:57












    The connection was working on the first attempt as well. If you see the first attempt error message from mysql, it tells him that the user doesn't have access from the container host, but the connection was ok. Who knows what happened to the access rights to allow connections from 172.18.0.4 or % for develop user between the attempts? What I recommended was running mysql inside another container, not on the host machine. But even if the author wants to do so I suggested mapping host into the container network with fixed ip
    – Alexey
    Nov 8 at 11:02






    The connection was working on the first attempt as well. If you see the first attempt error message from mysql, it tells him that the user doesn't have access from the container host, but the connection was ok. Who knows what happened to the access rights to allow connections from 172.18.0.4 or % for develop user between the attempts? What I recommended was running mysql inside another container, not on the host machine. But even if the author wants to do so I suggested mapping host into the container network with fixed ip
    – Alexey
    Nov 8 at 11:02














    up vote
    0
    down vote













    That is true, when we start docker container it is get their own ip for container. You need to map host port with docker container. then, when you try to connect host port it redirect to myssql docker container. Please look at https://docs.docker.com/config/containers/container-networking/






    share|improve this answer





















    • How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
      – Nico Haase
      Nov 8 at 10:57















    up vote
    0
    down vote













    That is true, when we start docker container it is get their own ip for container. You need to map host port with docker container. then, when you try to connect host port it redirect to myssql docker container. Please look at https://docs.docker.com/config/containers/container-networking/






    share|improve this answer





















    • How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
      – Nico Haase
      Nov 8 at 10:57













    up vote
    0
    down vote










    up vote
    0
    down vote









    That is true, when we start docker container it is get their own ip for container. You need to map host port with docker container. then, when you try to connect host port it redirect to myssql docker container. Please look at https://docs.docker.com/config/containers/container-networking/






    share|improve this answer












    That is true, when we start docker container it is get their own ip for container. You need to map host port with docker container. then, when you try to connect host port it redirect to myssql docker container. Please look at https://docs.docker.com/config/containers/container-networking/







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 8 at 10:07









    WGSSAMINTHA

    567




    567












    • How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
      – Nico Haase
      Nov 8 at 10:57


















    • How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
      – Nico Haase
      Nov 8 at 10:57
















    How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
    – Nico Haase
    Nov 8 at 10:57




    How does this solve the problem? According to the screenshot, the connection between the client container and the server is possible, but only on the second attempt
    – Nico Haase
    Nov 8 at 10:57










    up vote
    0
    down vote













    I'd suggest you to create a docker bridged network and then create your container using the --add-host as suggested by Alexey.



    In a simple script:



    DOCKER_NET_NAME='the_docker_network_name'
    DOCKER_GATEWAY='172.100.0.1'

    docker network create
    --driver bridge
    --subnet=172.100.0.0/16
    --gateway=$DOCKER_GATEWAY
    $DOCKER_NET_NAME

    docker run -d
    --add-host db.onthehost:$DOCKER_GATEWAY
    --restart=always
    --network=$DOCKER_NET_NAME
    --name=magicContainerName
    yourImage:latest


    EDIT: creating a network will also simplify the communication among containers (if you plan to have it in the future) since you'll be able to use the container names instead of their IP.






    share|improve this answer



























      up vote
      0
      down vote













      I'd suggest you to create a docker bridged network and then create your container using the --add-host as suggested by Alexey.



      In a simple script:



      DOCKER_NET_NAME='the_docker_network_name'
      DOCKER_GATEWAY='172.100.0.1'

      docker network create
      --driver bridge
      --subnet=172.100.0.0/16
      --gateway=$DOCKER_GATEWAY
      $DOCKER_NET_NAME

      docker run -d
      --add-host db.onthehost:$DOCKER_GATEWAY
      --restart=always
      --network=$DOCKER_NET_NAME
      --name=magicContainerName
      yourImage:latest


      EDIT: creating a network will also simplify the communication among containers (if you plan to have it in the future) since you'll be able to use the container names instead of their IP.






      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        I'd suggest you to create a docker bridged network and then create your container using the --add-host as suggested by Alexey.



        In a simple script:



        DOCKER_NET_NAME='the_docker_network_name'
        DOCKER_GATEWAY='172.100.0.1'

        docker network create
        --driver bridge
        --subnet=172.100.0.0/16
        --gateway=$DOCKER_GATEWAY
        $DOCKER_NET_NAME

        docker run -d
        --add-host db.onthehost:$DOCKER_GATEWAY
        --restart=always
        --network=$DOCKER_NET_NAME
        --name=magicContainerName
        yourImage:latest


        EDIT: creating a network will also simplify the communication among containers (if you plan to have it in the future) since you'll be able to use the container names instead of their IP.






        share|improve this answer














        I'd suggest you to create a docker bridged network and then create your container using the --add-host as suggested by Alexey.



        In a simple script:



        DOCKER_NET_NAME='the_docker_network_name'
        DOCKER_GATEWAY='172.100.0.1'

        docker network create
        --driver bridge
        --subnet=172.100.0.0/16
        --gateway=$DOCKER_GATEWAY
        $DOCKER_NET_NAME

        docker run -d
        --add-host db.onthehost:$DOCKER_GATEWAY
        --restart=always
        --network=$DOCKER_NET_NAME
        --name=magicContainerName
        yourImage:latest


        EDIT: creating a network will also simplify the communication among containers (if you plan to have it in the future) since you'll be able to use the container names instead of their IP.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 8 at 10:59

























        answered Nov 8 at 10:54









        Stefano

        1,031615




        1,031615






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52984913%2fmysql-connect-host-change-every-time-in-the-docker-container-why%23new-answer', 'question_page');
            }
            );

            Post as a guest




















































































            Popular posts from this blog

            Landwehr

            Reims

            Schenkenzell