In the below docker-compose file,
dbc:
image: mysql:5.6
hostname: db
expose:
- "3386"
environment:
MYSQL_DATABASE: somebackenddb
MYSQL_USER: user1
MYSQL_PASSWORD: pswd
MYSQL_ROOT_PASSWORD: pswd
agent:
image: somedockerhub/ansible
volumes:
- ../../whatever/x.yml:/whatever/y.yml
links:
- dbc
environment:
PROBE_HOST: "db"
PROBE_PORT: "3306"
we are using hostname
attribute in dbc
service.
agent
service is linked to that hostname
whose value is db
Generally, hostnames are given to virtual machines.
Every container is given an IP address, but,
For a container launched by dbc
service, what does hostname
mean for a container?
By default hostnames of a docker container is equal to their container id.
Defining attribute hostname: db
in docker-compose file will set hostname of dbc
service container to be db
.
If you enter the created container with docker exec -it [container_id] bash
and run command hostname
you should see db
.
Running hostname -i
would show virtual ip address.
cat /etc/hosts
would show: ... 172.17.0.4 db
Env. variable HOSTNAME insider container would equal db
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.