Environment Variables

If suppose the developer mentioned some –env (Environmental variables) in the source code by which we can connect to the database server, for example, Username and password then while creating the container we set the username and password as shown in the below command. 

docker run -d --name <name>  -e USERNAME=<***> -e  PASSWORD=<***>  --network <****> 

We can set the above-mentioned env variables to the database container by using the following command.

docker run -d -p <port> --name <name>  -e HOSTNAME=<***> -e  USERNAME=<***> -e  PASSWORD=<***> --network <***>

Docker – Container Linking

Docker is a set of platforms as a service (PaaS) products that use the Operating system level visualization to deliver software in packages called containers.There are times during the development of our application when we need two containers to be able to communicate with each other. It might be possible that the services of both containers are dependent on each other. This can be done with the help of Container Linking.

Previously the containers were used by using the “–link” flag but that has now become deprecated and is considered a legacy command.

 

Similar Reads

Connect with the Linking System

There are two ways of linking the containers...

The Importance of Naming

Docker mainly depends upon the names of the containers we can see in the above example whenever you create a new container the name gets created automatically we can also name our container is will us in two different ways....

Environment Variables

If suppose the developer mentioned some –env (Environmental variables) in the source code by which we can connect to the database server, for example, Username and password then while creating the container we set the username and password as shown in the below command....

Updating the /etc/hosts file

Docker adds a host entry for the source container to the /etc/hosts apart from the environmental variables we provide the command to link two containers is mentioned below....