Created
March 7, 2023 21:46
-
-
Save nballenger/79830b5a661855ec3a1a00bb2c6a9fb6 to your computer and use it in GitHub Desktop.
Attaching multiple compose clusters to a pre-existing Docker network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Should be in ./client_cluster/docker-compose.yml | |
services: | |
client_cluster: | |
container_name: client_container | |
build: | |
context: . | |
dockerfile: ./Dockerfile | |
networks: | |
- ctalk | |
networks: | |
ctalk: | |
name: cluster_talk | |
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Should be in ./server_cluster/docker-compose.yml | |
services: | |
server_container: | |
container_name: server_container | |
build: | |
context: . | |
dockerfile: ./Dockerfile | |
ports: | |
- 8000:8000 | |
networks: | |
- ctalk | |
networks: | |
ctalk: | |
name: cluster_talk | |
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Should be in ./client_cluster/Dockerfile | |
FROM python:3.9-bullseye | |
ADD ./entrypoint.sh /entrypoint.sh | |
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Should be in ./server_cluster/Dockerfile | |
FROM python:3.9-bullseye | |
RUN mkdir -p /var/www/html \ | |
&& echo "HELLO, WORLD" > /var/www/html/index.html | |
WORKDIR /var/www/html | |
ENTRYPOINT ["python3", "-m", "http.server", "8000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Should be in ./client_cluster/entrypoint.sh | |
sleep 3 | |
for i in 1 2 3 4 5 6 7 8 9; do | |
echo "Calling out to the server container:" | |
curl -s server_container:8000 | |
echo "Sleeping 3..." | |
sleep 3 | |
done | |
echo "Got to the last loop iteration, exiting." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Commands to execute to make them talk to each other on a Docker network | |
docker network create cluster_talk | |
cd server_cluster | |
docker-compose up -d | |
cd ../client_cluster | |
docker-compose up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment