I am new in Docker and Mongodb. I have a mongodb container with a database and collection. I created another container with php and apache using following command:
docker run -d -p 8020:80 --name my-php-apache php:7-apache
In order to be able to connect to mongodb container (my-mongo), i need to link this container to mongodb container. So i used following command to link both containers:
docker run -d -p 8020:80 --link my-mongo --name php-mongo-link php:7-apache
But it shows following error:
b36e400bb5c0d229f952a7b365d5a8bfed402410bdb5a802f29fd2fdc1ef28f9
docker: Error response from daemon: driver failed programming external connectivity on endpoint php-mongo-link (ec4eb66d0a314201c99f79eb4a09cf82ffb2fc399647020adaf34932878857b7): Bind for 0.0.0.0:8020 failed: port is already allocated.
To link the containers, should the ports of php-apache (8020:80) and php-mongo-link be same ? Or should they be different ? Is there any better way to link 2 containers (php-apache and mongodb) ? I just need to connect from the php container to the mongodb container to insert some data in the mongodb database.
my-php-apacheand thephp-mongo-linkcontainer; they both seem to be running the same image? Use bridge networks in the Docker documentation is probably what you're looking for, though it's not the most approachable explanation.