Skip to content

Commit 3b521d4

Browse files
authored
[ BAEL-6068 ] - Communicating with Docker containers on the same machine (#13343)
* fix: build clean up * feat: add docker compose 2 module, add communication same machine docker compose * fix: remove unused package lock file
1 parent 7f3f707 commit 3b521d4

13 files changed

Lines changed: 177 additions & 4 deletions

File tree

docker-modules/docker-caching/multi-module-caching/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.baeldung</groupId>
77
<artifactId>multi-module-caching</artifactId>
@@ -25,6 +25,7 @@
2525
</dependencyManagement>
2626

2727
<properties>
28+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2829
<java.version>1.8</java.version>
2930
<guava.version>31.1-jre</guava.version>
3031
</properties>

docker-modules/docker-caching/single-module-caching/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.baeldung</groupId>
77
<artifactId>single-module-caching</artifactId>
@@ -48,6 +48,7 @@
4848
<properties>
4949
<maven.compiler.source>8</maven.compiler.source>
5050
<maven.compiler.target>8</maven.compiler.target>
51+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5152
<guava.version>31.1-jre</guava.version>
5253
</properties>
5354

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## Relevant Articles:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM alpine:latest
2+
MAINTAINER baeldung.com
3+
RUN apk update && apk add iputils && apk add bash && apk add curl
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM node:8.16.1-alpine
2+
WORKDIR /app
3+
COPY host_docker_internal/package.json /app
4+
COPY host_docker_internal/index.js /app
5+
RUN npm install
6+
CMD node index.js
7+
EXPOSE 8080
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
services:
2+
alpine-app-1:
3+
container_name: alpine-app-1
4+
image: alpine-app-1
5+
build:
6+
context: ..
7+
dockerfile: Dockerfile
8+
tty: true
9+
ports:
10+
- 8081:8081
11+
12+
alpine-app-2:
13+
container_name: alpine-app-2
14+
image: alpine-app-2
15+
build:
16+
context: ..
17+
dockerfile: Dockerfile
18+
tty: true
19+
ports:
20+
- 8080:8080
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
services:
2+
alpine-app-1:
3+
container_name: alpine-app-1
4+
extra_hosts: # for linux hosts since version 20.10
5+
- host.docker.internal:host-gateway
6+
build:
7+
context: ..
8+
dockerfile: Dockerfile
9+
image: alpine-app-1
10+
tty: true
11+
networks:
12+
- first-network
13+
14+
node-app:
15+
container_name: node-app
16+
build:
17+
context: ..
18+
dockerfile: Dockerfile.node
19+
image: node-app
20+
ports:
21+
- 8080:8080
22+
networks:
23+
- second-network
24+
25+
networks:
26+
first-network:
27+
driver: bridge
28+
second-network:
29+
driver: bridge
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var express = require('express')
2+
var app = express()
3+
4+
app.get('/', function (req, res) {
5+
res.send('Hello World!')
6+
})
7+
8+
app.listen(8080, function () {
9+
console.log('app listening on port 8080!')
10+
})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "host_docker_internal",
3+
"version": "1.0.0",
4+
"description": "node js app",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "Baeldung",
10+
"license": "ISC",
11+
"dependencies": {
12+
"express": "^4.18.2"
13+
}
14+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
services:
2+
alpine-app-1:
3+
container_name: alpine-app-1
4+
build:
5+
context: ..
6+
dockerfile: Dockerfile
7+
image: alpine-app-1
8+
tty: true
9+
ports:
10+
- 8080:8080
11+
networks:
12+
network-example:
13+
ipv4_address: 10.5.0.2
14+
15+
alpine-app-2:
16+
container_name: alpine-app-2
17+
build:
18+
context: ..
19+
dockerfile: Dockerfile
20+
image: alpine-app-2
21+
tty: true
22+
ports:
23+
- 8081:8081
24+
networks:
25+
network-example:
26+
ipv4_address: 10.5.0.3
27+
28+
networks:
29+
network-example:
30+
driver: bridge
31+
ipam:
32+
config:
33+
- subnet: 10.5.0.0/16
34+
gateway: 10.5.0.1

0 commit comments

Comments
 (0)