Hello,
I have two separate containers, each of which has its own YAML files. Do I need to configure the network to connect these two containers? Or can I connect these two containers by editing the YAML file?
Cheers.
Share and learn in the Docker community.
Hello,
I have two separate containers, each of which has its own YAML files. Do I need to configure the network to connect these two containers? Or can I connect these two containers by editing the YAML file?
Cheers.
You can have two yaml files in a single Compose project so the question is whether you have two compose projects or not. I thought I already shared the following links with you, but I canât find it in your other topics so it seems I remembered wrong.
Recommended links to learn the basics and concepts:
The last link is (currently) about Docker Desktop which is Docker CE in a virtual machine whith a GUI.
The answer to your qustion is in my tutorial. You need a common external network attached to both compose projects.
Donât be confused by the title. I share it not because of the ports, but because of the shared network between compose projects.
Hello,
Thank you so much for your reply.
Let me be more clear. I have two directories named PHP and Apache, each of which is a separate container and each has its own YAML file. I want to connect these two containers. Does this connection take place through the YAML file or the network?
https://learn-docker.it-sziget.hu/en/latest/pages/projects/p06.html tutorial is a bit dumb for me. Does PHP want to communicate with Apache through Nginx?
Again, please, read the suggested tutorials because even your question doesnât make sense.
I suppose you didnât mean what you wrote and you donât think the tutorial is dumb. If you donât understand it, you need to learn the basics. Sorry, but we canât teach you everĂthing from the beginning.
Note: Two folders still doesnât mean two compose projects, but in your case Iâm pretty sure you meant that. I wouldnât have created to separate compose projects for PHP and Apache. First of all, there is a PHP image variant with Apache HTTPD in it, which is better for beginners, an second, those should be in a single compose project for each website.
Hello,
Was not my question clear? I know that I can define and connect Apache and PHP in one YMAL file. Suppose I have a directory called PHP and in this directory there is a YAML file related to the PHP container. I have another directory named Apache and in this directory there is a YAML file related to Apache container. I have two separate containers. Now I want to connect these two containers. Is this connection done through another YAML file or setting the network in both existing YAML files.
Hello,
I took a look at some cheat sheets about Docker.
1- Your example uses Nginx as a proxy, is this mandatory to connect two containers?
2- I have a directory named Nginx that contains a YAML file as follows:
version: '3.9'
services:
web:
image: nginx:latest
ports:
- '80:80'
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
- /var/www/html:/usr/share/nginx/html
links:
- php-fpm
php-fpm:
image: php:8-fpm
volumes:
- /var/www/html:/usr/share/nginx/html/
I have another directory called Apache that has a YAML file like this:
version: '3.9'
services:
httpd:
image: 'httpd:latest'
ports:
- '8080:80'
volumes:
- '/var/www/html:/usr/local/apache2/htdocs/'
I want Apache to use the PHP that is in the other container. Please guide me on this.
Thank you.
There is no need to YAML files to connect the two container. For this you have to create a Docker network, this allow to communicate between the container. Then run both the container on the same network.
Hi,
Thank you so much for your reply.
Can you introduce me a tutorial for this work or edit the above files to create a network?