hack3rcon
(Hack3rcon)
March 27, 2024, 1:37pm
1
Hello,
I networked a few containers that were in two YAML files:
First Container:
version: '3.9'
networks:
Container1:
driver: bridge
name: My_Net
...
Second Container:
version: '3.9'
networks:
Container2:
external: true
name: My_Net
...
Now I want to add another YAML file to this network. Can the configuration of this third container be something like the following?
version: '3.9'
networks:
Container3:
external: true
name: My_Net
...
Cheers.
Hello.
I think it will work well if you set it up on a network called My_Net that is already created.
And since we use the same network, I think container 2 and container 3 will be well communicated.
Did I not figure out the problem?
Please reply.
Best Regards.
limsangwoon
1 Like
hack3rcon
(Hack3rcon)
March 27, 2024, 8:46pm
3
Hello,
Thank you so much for your reply.
So, I have to use external: true
for the third container. I want all three containers to be able to communicate with each other.
1 Like
Hello,
2 containers with each different network area have different bands, so communication is impossible.
But you can add two networks to one container as shown in the picture. How about communicating this way?
The command used this and if thereโs any other way Iโd like to share it
docker network connect My_Net <container name>
Best Regards
limsangwoons
1 Like
hack3rcon
(Hack3rcon)
March 28, 2024, 8:23am
5
Hello,
Thanks again.
But with the above configuration, containers can ping each other. Do I still need the docker network connect My_Net <container name>
command?
hello
Then, I think I need more detailed file information, so can you deliver a file that runs even the container?
Best Regards
limsangwoons
hack3rcon
(Hack3rcon)
March 28, 2024, 12:57pm
7
Hi,
Thanks again.
Sure.
YAML file 1 :
version: '3.9'
networks:
NginxPHP:
driver: bridge
name: My_Net
services:
web:
image: nginx:latest
container_name: Nginx
ports:
- '8080:80'
volumes:
# - ./default.conf:/etc/nginx/conf.d/default.conf
- /var/www/html:/usr/share/nginx/html
networks:
- NginxPHP
depends_on:
- php-fpm
php-fpm:
image: php:8-fpm
container_name: PHP
volumes:
- /var/www/html:/usr/share/nginx/html/
- /var/www/html:/usr/local/apache2/htdocs/
networks:
- NginxPHP
YAML file 2 :
version: '3.9'
networks:
Apache:
external: true
name: My_Net
services:
httpd:
ports:
- '80:80'
volumes:
- /var/www/html:/usr/local/apache2/htdocs/
# - ./httpd.conf:/usr/local/apache2/conf/httpd.conf
image: 'httpd:latest'
container_name: Apache
networks:
- Apache
As you can see, all 3 containers can ping each other.
hack3rcon
(Hack3rcon)
March 29, 2024, 8:35am
8
Hello,
When containers ping each other, it means that the connection between them is established. Is it right? Is it necessary to docker network connect My_Net <container name>
command?
Cheers.
Hello.
Iโm sorry. I made a mistake.
After all, all three containers use the same my_net, so itโs right to communicate well with each other.
You can forget the command I gave you.
Best Regards,
limsangwoon
1 Like
hack3rcon
(Hack3rcon)
March 29, 2024, 2:21pm
10
Hi,
Thanks again.
I remove the networks section from the YAML files and use the following commands instead:
# docker network create My_Net
# docker network connect My_Net Nginx
# docker network connect My_Net PHP
# docker network connect My_Net Apache
Is it the same thing?