In docker compose we have external_links option, but how it work?

Just link writes to /etc/hosts, but external_links is not.

Please explain how this option is working, because in docks no one words about it.


1 Answer 1


When you create a docker-compose.yml like this:

version: '2'

    image: alpine
    command: sleep 3600
      - google.com:

And do not specify a default network configuration, the docker-compose actually creates a custom default network by the name of the folder you are running the docker-compose up command:

[myserver:external-links-test] docker-compose up
Creating network "externallinkstest_default" with the default driver
Creating externallinkstest_sleep-one-hour_1
Attaching to externallinkstest_sleep-one-hour_1

Then the container is created and joins this custom network, and the external link is set when the container joins the network. You can inspect the recently created container and see for yourself:

[myserver:~] docker inspect 1056bb135bc0
        "Id": "1056bb135bc0200dcfff1fa25affd561042e0515641adf435e4b63a16903f93d",
        "Created": "2017-01-26T14:31:57.928385177Z",
        ... other info ...
        "NetworkSettings": {
            ... other info ...
            "Networks": {
                "externallinkstest_default": {
                    "IPAMConfig": null,
                    "Links": [
                    "Aliases": [
                    "NetworkID": "343121714be4750eebf12997fa73c3aaba0f2cf5faace633ab1ca683a2959632",
                    "EndpointID": "74f1a975236a8ab0f60379408faa04022f1b9e398c7b8a541158c4ca889aff98",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:14:00:02"

The docker-compose up actually translates to something like this in pure docker commands:

[myserver:external-links-test] docker network create --attachable --subnet externallinkstest_default
[myserver:external-links-test] docker run -d --name externallinkstest_sleep-one-hour_1 alpine sleep 3600
[myserver:external-links-test] docker network connect --link google.com: externallinkstest_default externallinkstest_sleep-one-hour_1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.