how app server know how to connect to the mysql host without network

113 Views Asked by At

I am using joget with docker:

# create a volume container for shared data
docker volume create jogetdata

# run a MySQL database container
docker run -d --name jogetdb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=jwdb -e MYSQL_USER=joget -e MYSQL_PASSWORD=joget -e MYSQL_DATABASE=jwdb mysql:5.7

# run a Joget Workflow container
docker run -d --link jogetdb:jwdb --name joget -p 8080:8080 -e MYSQL_HOST=jwdb -e MYSQL_DATABASE=jwdb -e MYSQL_PORT=3306 -e MYSQL_USER=joget -e MYSQL_PASSWORD=joget --mount source=jogetdata,target=/opt/joget/wflow jogetworkflow/joget-enterprise

I am just curious why joget is able to connect to the mysql sever using MYSQL_HOST=jwdb? I didn't use any network here?

1

There are 1 best solutions below

0
On BEST ANSWER

For linked containers, Docker adds an entry in the /etc/hosts file for you, this way you are use the name as a host name and don't have to worry about the name resolution.

If you check /etc/hosts in the container you'll see that it matches the IP addresses within your docker network.