How Do I Set Hostname in Docker Compose?
up vote
51
down vote
favorite
In my docker-compose.yml file, I have the following. However the container does not pick up the hostname value. Any ideas?
dns:
image: phensley/docker-dns
hostname: affy
domainname: affy.com
volumes:
- /var/run/docker.sock:/docker.sock
docker docker-compose
add a comment |
up vote
51
down vote
favorite
In my docker-compose.yml file, I have the following. However the container does not pick up the hostname value. Any ideas?
dns:
image: phensley/docker-dns
hostname: affy
domainname: affy.com
volumes:
- /var/run/docker.sock:/docker.sock
docker docker-compose
2
I have edited your question to correctly display preformatted text. This makes it much more readable.
– larsks
Apr 28 '15 at 17:02
1
What version of Compose are you using?
– kojiro
Apr 28 '15 at 17:51
add a comment |
up vote
51
down vote
favorite
up vote
51
down vote
favorite
In my docker-compose.yml file, I have the following. However the container does not pick up the hostname value. Any ideas?
dns:
image: phensley/docker-dns
hostname: affy
domainname: affy.com
volumes:
- /var/run/docker.sock:/docker.sock
docker docker-compose
In my docker-compose.yml file, I have the following. However the container does not pick up the hostname value. Any ideas?
dns:
image: phensley/docker-dns
hostname: affy
domainname: affy.com
volumes:
- /var/run/docker.sock:/docker.sock
docker docker-compose
docker docker-compose
edited May 16 at 17:12
Wilfred Hughes
16.4k1091128
16.4k1091128
asked Apr 28 '15 at 16:25
David Medinets
2,53321716
2,53321716
2
I have edited your question to correctly display preformatted text. This makes it much more readable.
– larsks
Apr 28 '15 at 17:02
1
What version of Compose are you using?
– kojiro
Apr 28 '15 at 17:51
add a comment |
2
I have edited your question to correctly display preformatted text. This makes it much more readable.
– larsks
Apr 28 '15 at 17:02
1
What version of Compose are you using?
– kojiro
Apr 28 '15 at 17:51
2
2
I have edited your question to correctly display preformatted text. This makes it much more readable.
– larsks
Apr 28 '15 at 17:02
I have edited your question to correctly display preformatted text. This makes it much more readable.
– larsks
Apr 28 '15 at 17:02
1
1
What version of Compose are you using?
– kojiro
Apr 28 '15 at 17:51
What version of Compose are you using?
– kojiro
Apr 28 '15 at 17:51
add a comment |
4 Answers
4
active
oldest
votes
up vote
8
down vote
accepted
I found that the hostname was not visible to other containers when using docker run
. This turns out to be a known issue (perhaps more a known feature), with part of the discussion being:
We should probably add a warning to the docs about using hostname. I think it is rarely useful.
The correct way of assigning a hostname - in terms of container networking - is to define an alias like so:
services:
some-service:
networks:
some-network:
aliases:
- alias1
- alias2
Unfortunately this still doesn't work with docker run
. The workaround is to assign the container a name:
docker-compose run --name alias1 some-service
And alias1
can then be pinged from the other containers.
1
I'm stuck with that problem that I can't access container by hosname from other containers. And you're the only one in whole internet who stated this problem.. been googling for 20 hours already
– holms
Apr 9 at 3:47
add a comment |
up vote
31
down vote
This seems to work correctly. If I put your config into a file:
$ cat > compose.yml <<EOF
dns:
image: phensley/docker-dns
hostname: affy
domainname: affy.com
volumes:
- /var/run/docker.sock:/docker.sock
EOF
And then bring things up:
$ docker-compose -f compose.yml up
Creating tmp_dns_1...
Attaching to tmp_dns_1
dns_1 | 2015-04-28T17:47:45.423387 [dockerdns] table.add tmp_dns_1.docker -> 172.17.0.5
And then check the hostname inside the container, everything seems to be fine:
$ docker exec -it stack_dns_1 hostname
affy.affy.com
What version of Compose are you using?
– kojiro
Apr 28 '15 at 17:52
This format doesn't work in the latest version of docker-compose. YML files are finicky things; are you sure this is the right format for dns?
– George Stocker♦
Nov 24 '15 at 3:08
2
YML files aren't really all that finicky. What does "doesn't work" mean? According to the docs, bothhostname
anddomainname
are validdocker-compose.yml
options. Update: just tested, still seems to work just fine (docker-compose version 1.4.2, docker version 1.8.2).
– larsks
Nov 24 '15 at 12:45
Is there any way to expose this hostname outside of the docker environment? It would be nice if the host could access the docker containers by their dns name.
– Paul Praet
Apr 6 '16 at 8:21
That is possible, and probably worth it's own question. If you search for "docker dns" you will find several relevant results; take a look at what's out there first.
– larsks
Apr 6 '16 at 11:27
add a comment |
up vote
16
down vote
Based on docker documentation:
https://docs.docker.com/compose/compose-file/#/command
I simply put
hostname: <string>
in my docker-compose file.
E.g.:
[...]
lb01:
hostname: at-lb01
image: at-client-base:v1
[...]
and container lb01 picks up at-lb01
as hostname.
if you have multiple containers in the docker-compose file, would you set the hostname for each container? that seems very inefficient?
– vgoklani
Sep 19 '17 at 10:13
1
If you need well-known names for containers that's a viable solution.
– Marcello Romani
Oct 2 '17 at 11:48
add a comment |
up vote
2
down vote
I needed to spin freeipa container to have a working kdc and had to give it a hostname otherwise it wouldn't run.
What eventually did work for me is setting the HOSTNAME
env variable in compose:
version: 2
services:
freeipa:
environment:
- HOSTNAME=ipa.example.test
Now its working:
docker exec -it freeipa_freeipa_1 hostname
ipa.example.test
1
For me, using slim, that results in a HOSTNAME environment variable that has no effect at all on the actual hostname of the container
– Oliver Dungey
Oct 18 at 13:52
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
I found that the hostname was not visible to other containers when using docker run
. This turns out to be a known issue (perhaps more a known feature), with part of the discussion being:
We should probably add a warning to the docs about using hostname. I think it is rarely useful.
The correct way of assigning a hostname - in terms of container networking - is to define an alias like so:
services:
some-service:
networks:
some-network:
aliases:
- alias1
- alias2
Unfortunately this still doesn't work with docker run
. The workaround is to assign the container a name:
docker-compose run --name alias1 some-service
And alias1
can then be pinged from the other containers.
1
I'm stuck with that problem that I can't access container by hosname from other containers. And you're the only one in whole internet who stated this problem.. been googling for 20 hours already
– holms
Apr 9 at 3:47
add a comment |
up vote
8
down vote
accepted
I found that the hostname was not visible to other containers when using docker run
. This turns out to be a known issue (perhaps more a known feature), with part of the discussion being:
We should probably add a warning to the docs about using hostname. I think it is rarely useful.
The correct way of assigning a hostname - in terms of container networking - is to define an alias like so:
services:
some-service:
networks:
some-network:
aliases:
- alias1
- alias2
Unfortunately this still doesn't work with docker run
. The workaround is to assign the container a name:
docker-compose run --name alias1 some-service
And alias1
can then be pinged from the other containers.
1
I'm stuck with that problem that I can't access container by hosname from other containers. And you're the only one in whole internet who stated this problem.. been googling for 20 hours already
– holms
Apr 9 at 3:47
add a comment |
up vote
8
down vote
accepted
up vote
8
down vote
accepted
I found that the hostname was not visible to other containers when using docker run
. This turns out to be a known issue (perhaps more a known feature), with part of the discussion being:
We should probably add a warning to the docs about using hostname. I think it is rarely useful.
The correct way of assigning a hostname - in terms of container networking - is to define an alias like so:
services:
some-service:
networks:
some-network:
aliases:
- alias1
- alias2
Unfortunately this still doesn't work with docker run
. The workaround is to assign the container a name:
docker-compose run --name alias1 some-service
And alias1
can then be pinged from the other containers.
I found that the hostname was not visible to other containers when using docker run
. This turns out to be a known issue (perhaps more a known feature), with part of the discussion being:
We should probably add a warning to the docs about using hostname. I think it is rarely useful.
The correct way of assigning a hostname - in terms of container networking - is to define an alias like so:
services:
some-service:
networks:
some-network:
aliases:
- alias1
- alias2
Unfortunately this still doesn't work with docker run
. The workaround is to assign the container a name:
docker-compose run --name alias1 some-service
And alias1
can then be pinged from the other containers.
answered Nov 13 '17 at 12:10
foz
1,1701314
1,1701314
1
I'm stuck with that problem that I can't access container by hosname from other containers. And you're the only one in whole internet who stated this problem.. been googling for 20 hours already
– holms
Apr 9 at 3:47
add a comment |
1
I'm stuck with that problem that I can't access container by hosname from other containers. And you're the only one in whole internet who stated this problem.. been googling for 20 hours already
– holms
Apr 9 at 3:47
1
1
I'm stuck with that problem that I can't access container by hosname from other containers. And you're the only one in whole internet who stated this problem.. been googling for 20 hours already
– holms
Apr 9 at 3:47
I'm stuck with that problem that I can't access container by hosname from other containers. And you're the only one in whole internet who stated this problem.. been googling for 20 hours already
– holms
Apr 9 at 3:47
add a comment |
up vote
31
down vote
This seems to work correctly. If I put your config into a file:
$ cat > compose.yml <<EOF
dns:
image: phensley/docker-dns
hostname: affy
domainname: affy.com
volumes:
- /var/run/docker.sock:/docker.sock
EOF
And then bring things up:
$ docker-compose -f compose.yml up
Creating tmp_dns_1...
Attaching to tmp_dns_1
dns_1 | 2015-04-28T17:47:45.423387 [dockerdns] table.add tmp_dns_1.docker -> 172.17.0.5
And then check the hostname inside the container, everything seems to be fine:
$ docker exec -it stack_dns_1 hostname
affy.affy.com
What version of Compose are you using?
– kojiro
Apr 28 '15 at 17:52
This format doesn't work in the latest version of docker-compose. YML files are finicky things; are you sure this is the right format for dns?
– George Stocker♦
Nov 24 '15 at 3:08
2
YML files aren't really all that finicky. What does "doesn't work" mean? According to the docs, bothhostname
anddomainname
are validdocker-compose.yml
options. Update: just tested, still seems to work just fine (docker-compose version 1.4.2, docker version 1.8.2).
– larsks
Nov 24 '15 at 12:45
Is there any way to expose this hostname outside of the docker environment? It would be nice if the host could access the docker containers by their dns name.
– Paul Praet
Apr 6 '16 at 8:21
That is possible, and probably worth it's own question. If you search for "docker dns" you will find several relevant results; take a look at what's out there first.
– larsks
Apr 6 '16 at 11:27
add a comment |
up vote
31
down vote
This seems to work correctly. If I put your config into a file:
$ cat > compose.yml <<EOF
dns:
image: phensley/docker-dns
hostname: affy
domainname: affy.com
volumes:
- /var/run/docker.sock:/docker.sock
EOF
And then bring things up:
$ docker-compose -f compose.yml up
Creating tmp_dns_1...
Attaching to tmp_dns_1
dns_1 | 2015-04-28T17:47:45.423387 [dockerdns] table.add tmp_dns_1.docker -> 172.17.0.5
And then check the hostname inside the container, everything seems to be fine:
$ docker exec -it stack_dns_1 hostname
affy.affy.com
What version of Compose are you using?
– kojiro
Apr 28 '15 at 17:52
This format doesn't work in the latest version of docker-compose. YML files are finicky things; are you sure this is the right format for dns?
– George Stocker♦
Nov 24 '15 at 3:08
2
YML files aren't really all that finicky. What does "doesn't work" mean? According to the docs, bothhostname
anddomainname
are validdocker-compose.yml
options. Update: just tested, still seems to work just fine (docker-compose version 1.4.2, docker version 1.8.2).
– larsks
Nov 24 '15 at 12:45
Is there any way to expose this hostname outside of the docker environment? It would be nice if the host could access the docker containers by their dns name.
– Paul Praet
Apr 6 '16 at 8:21
That is possible, and probably worth it's own question. If you search for "docker dns" you will find several relevant results; take a look at what's out there first.
– larsks
Apr 6 '16 at 11:27
add a comment |
up vote
31
down vote
up vote
31
down vote
This seems to work correctly. If I put your config into a file:
$ cat > compose.yml <<EOF
dns:
image: phensley/docker-dns
hostname: affy
domainname: affy.com
volumes:
- /var/run/docker.sock:/docker.sock
EOF
And then bring things up:
$ docker-compose -f compose.yml up
Creating tmp_dns_1...
Attaching to tmp_dns_1
dns_1 | 2015-04-28T17:47:45.423387 [dockerdns] table.add tmp_dns_1.docker -> 172.17.0.5
And then check the hostname inside the container, everything seems to be fine:
$ docker exec -it stack_dns_1 hostname
affy.affy.com
This seems to work correctly. If I put your config into a file:
$ cat > compose.yml <<EOF
dns:
image: phensley/docker-dns
hostname: affy
domainname: affy.com
volumes:
- /var/run/docker.sock:/docker.sock
EOF
And then bring things up:
$ docker-compose -f compose.yml up
Creating tmp_dns_1...
Attaching to tmp_dns_1
dns_1 | 2015-04-28T17:47:45.423387 [dockerdns] table.add tmp_dns_1.docker -> 172.17.0.5
And then check the hostname inside the container, everything seems to be fine:
$ docker exec -it stack_dns_1 hostname
affy.affy.com
answered Apr 28 '15 at 17:48
larsks
111k18182194
111k18182194
What version of Compose are you using?
– kojiro
Apr 28 '15 at 17:52
This format doesn't work in the latest version of docker-compose. YML files are finicky things; are you sure this is the right format for dns?
– George Stocker♦
Nov 24 '15 at 3:08
2
YML files aren't really all that finicky. What does "doesn't work" mean? According to the docs, bothhostname
anddomainname
are validdocker-compose.yml
options. Update: just tested, still seems to work just fine (docker-compose version 1.4.2, docker version 1.8.2).
– larsks
Nov 24 '15 at 12:45
Is there any way to expose this hostname outside of the docker environment? It would be nice if the host could access the docker containers by their dns name.
– Paul Praet
Apr 6 '16 at 8:21
That is possible, and probably worth it's own question. If you search for "docker dns" you will find several relevant results; take a look at what's out there first.
– larsks
Apr 6 '16 at 11:27
add a comment |
What version of Compose are you using?
– kojiro
Apr 28 '15 at 17:52
This format doesn't work in the latest version of docker-compose. YML files are finicky things; are you sure this is the right format for dns?
– George Stocker♦
Nov 24 '15 at 3:08
2
YML files aren't really all that finicky. What does "doesn't work" mean? According to the docs, bothhostname
anddomainname
are validdocker-compose.yml
options. Update: just tested, still seems to work just fine (docker-compose version 1.4.2, docker version 1.8.2).
– larsks
Nov 24 '15 at 12:45
Is there any way to expose this hostname outside of the docker environment? It would be nice if the host could access the docker containers by their dns name.
– Paul Praet
Apr 6 '16 at 8:21
That is possible, and probably worth it's own question. If you search for "docker dns" you will find several relevant results; take a look at what's out there first.
– larsks
Apr 6 '16 at 11:27
What version of Compose are you using?
– kojiro
Apr 28 '15 at 17:52
What version of Compose are you using?
– kojiro
Apr 28 '15 at 17:52
This format doesn't work in the latest version of docker-compose. YML files are finicky things; are you sure this is the right format for dns?
– George Stocker♦
Nov 24 '15 at 3:08
This format doesn't work in the latest version of docker-compose. YML files are finicky things; are you sure this is the right format for dns?
– George Stocker♦
Nov 24 '15 at 3:08
2
2
YML files aren't really all that finicky. What does "doesn't work" mean? According to the docs, both
hostname
and domainname
are valid docker-compose.yml
options. Update: just tested, still seems to work just fine (docker-compose version 1.4.2, docker version 1.8.2).– larsks
Nov 24 '15 at 12:45
YML files aren't really all that finicky. What does "doesn't work" mean? According to the docs, both
hostname
and domainname
are valid docker-compose.yml
options. Update: just tested, still seems to work just fine (docker-compose version 1.4.2, docker version 1.8.2).– larsks
Nov 24 '15 at 12:45
Is there any way to expose this hostname outside of the docker environment? It would be nice if the host could access the docker containers by their dns name.
– Paul Praet
Apr 6 '16 at 8:21
Is there any way to expose this hostname outside of the docker environment? It would be nice if the host could access the docker containers by their dns name.
– Paul Praet
Apr 6 '16 at 8:21
That is possible, and probably worth it's own question. If you search for "docker dns" you will find several relevant results; take a look at what's out there first.
– larsks
Apr 6 '16 at 11:27
That is possible, and probably worth it's own question. If you search for "docker dns" you will find several relevant results; take a look at what's out there first.
– larsks
Apr 6 '16 at 11:27
add a comment |
up vote
16
down vote
Based on docker documentation:
https://docs.docker.com/compose/compose-file/#/command
I simply put
hostname: <string>
in my docker-compose file.
E.g.:
[...]
lb01:
hostname: at-lb01
image: at-client-base:v1
[...]
and container lb01 picks up at-lb01
as hostname.
if you have multiple containers in the docker-compose file, would you set the hostname for each container? that seems very inefficient?
– vgoklani
Sep 19 '17 at 10:13
1
If you need well-known names for containers that's a viable solution.
– Marcello Romani
Oct 2 '17 at 11:48
add a comment |
up vote
16
down vote
Based on docker documentation:
https://docs.docker.com/compose/compose-file/#/command
I simply put
hostname: <string>
in my docker-compose file.
E.g.:
[...]
lb01:
hostname: at-lb01
image: at-client-base:v1
[...]
and container lb01 picks up at-lb01
as hostname.
if you have multiple containers in the docker-compose file, would you set the hostname for each container? that seems very inefficient?
– vgoklani
Sep 19 '17 at 10:13
1
If you need well-known names for containers that's a viable solution.
– Marcello Romani
Oct 2 '17 at 11:48
add a comment |
up vote
16
down vote
up vote
16
down vote
Based on docker documentation:
https://docs.docker.com/compose/compose-file/#/command
I simply put
hostname: <string>
in my docker-compose file.
E.g.:
[...]
lb01:
hostname: at-lb01
image: at-client-base:v1
[...]
and container lb01 picks up at-lb01
as hostname.
Based on docker documentation:
https://docs.docker.com/compose/compose-file/#/command
I simply put
hostname: <string>
in my docker-compose file.
E.g.:
[...]
lb01:
hostname: at-lb01
image: at-client-base:v1
[...]
and container lb01 picks up at-lb01
as hostname.
edited Nov 25 '17 at 17:14
answered Nov 1 '16 at 23:39
Marcello Romani
1,3451422
1,3451422
if you have multiple containers in the docker-compose file, would you set the hostname for each container? that seems very inefficient?
– vgoklani
Sep 19 '17 at 10:13
1
If you need well-known names for containers that's a viable solution.
– Marcello Romani
Oct 2 '17 at 11:48
add a comment |
if you have multiple containers in the docker-compose file, would you set the hostname for each container? that seems very inefficient?
– vgoklani
Sep 19 '17 at 10:13
1
If you need well-known names for containers that's a viable solution.
– Marcello Romani
Oct 2 '17 at 11:48
if you have multiple containers in the docker-compose file, would you set the hostname for each container? that seems very inefficient?
– vgoklani
Sep 19 '17 at 10:13
if you have multiple containers in the docker-compose file, would you set the hostname for each container? that seems very inefficient?
– vgoklani
Sep 19 '17 at 10:13
1
1
If you need well-known names for containers that's a viable solution.
– Marcello Romani
Oct 2 '17 at 11:48
If you need well-known names for containers that's a viable solution.
– Marcello Romani
Oct 2 '17 at 11:48
add a comment |
up vote
2
down vote
I needed to spin freeipa container to have a working kdc and had to give it a hostname otherwise it wouldn't run.
What eventually did work for me is setting the HOSTNAME
env variable in compose:
version: 2
services:
freeipa:
environment:
- HOSTNAME=ipa.example.test
Now its working:
docker exec -it freeipa_freeipa_1 hostname
ipa.example.test
1
For me, using slim, that results in a HOSTNAME environment variable that has no effect at all on the actual hostname of the container
– Oliver Dungey
Oct 18 at 13:52
add a comment |
up vote
2
down vote
I needed to spin freeipa container to have a working kdc and had to give it a hostname otherwise it wouldn't run.
What eventually did work for me is setting the HOSTNAME
env variable in compose:
version: 2
services:
freeipa:
environment:
- HOSTNAME=ipa.example.test
Now its working:
docker exec -it freeipa_freeipa_1 hostname
ipa.example.test
1
For me, using slim, that results in a HOSTNAME environment variable that has no effect at all on the actual hostname of the container
– Oliver Dungey
Oct 18 at 13:52
add a comment |
up vote
2
down vote
up vote
2
down vote
I needed to spin freeipa container to have a working kdc and had to give it a hostname otherwise it wouldn't run.
What eventually did work for me is setting the HOSTNAME
env variable in compose:
version: 2
services:
freeipa:
environment:
- HOSTNAME=ipa.example.test
Now its working:
docker exec -it freeipa_freeipa_1 hostname
ipa.example.test
I needed to spin freeipa container to have a working kdc and had to give it a hostname otherwise it wouldn't run.
What eventually did work for me is setting the HOSTNAME
env variable in compose:
version: 2
services:
freeipa:
environment:
- HOSTNAME=ipa.example.test
Now its working:
docker exec -it freeipa_freeipa_1 hostname
ipa.example.test
answered Mar 8 at 7:42
Roy Golan
713
713
1
For me, using slim, that results in a HOSTNAME environment variable that has no effect at all on the actual hostname of the container
– Oliver Dungey
Oct 18 at 13:52
add a comment |
1
For me, using slim, that results in a HOSTNAME environment variable that has no effect at all on the actual hostname of the container
– Oliver Dungey
Oct 18 at 13:52
1
1
For me, using slim, that results in a HOSTNAME environment variable that has no effect at all on the actual hostname of the container
– Oliver Dungey
Oct 18 at 13:52
For me, using slim, that results in a HOSTNAME environment variable that has no effect at all on the actual hostname of the container
– Oliver Dungey
Oct 18 at 13:52
add a comment |
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.
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%2fstackoverflow.com%2fquestions%2f29924843%2fhow-do-i-set-hostname-in-docker-compose%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
2
I have edited your question to correctly display preformatted text. This makes it much more readable.
– larsks
Apr 28 '15 at 17:02
1
What version of Compose are you using?
– kojiro
Apr 28 '15 at 17:51