[ 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
This commit is contained in:
parent
7f3f707077
commit
3b521d448f
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>multi-module-caching</artifactId>
|
||||
@ -25,6 +25,7 @@
|
||||
</dependencyManagement>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<guava.version>31.1-jre</guava.version>
|
||||
</properties>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>single-module-caching</artifactId>
|
||||
@ -48,6 +48,7 @@
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<guava.version>31.1-jre</guava.version>
|
||||
</properties>
|
||||
|
||||
|
1
docker-modules/docker-compose-2/README.md
Normal file
1
docker-modules/docker-compose-2/README.md
Normal file
@ -0,0 +1 @@
|
||||
## Relevant Articles:
|
@ -0,0 +1,3 @@
|
||||
FROM alpine:latest
|
||||
MAINTAINER baeldung.com
|
||||
RUN apk update && apk add iputils && apk add bash && apk add curl
|
@ -0,0 +1,7 @@
|
||||
FROM node:8.16.1-alpine
|
||||
WORKDIR /app
|
||||
COPY host_docker_internal/package.json /app
|
||||
COPY host_docker_internal/index.js /app
|
||||
RUN npm install
|
||||
CMD node index.js
|
||||
EXPOSE 8080
|
@ -0,0 +1,20 @@
|
||||
services:
|
||||
alpine-app-1:
|
||||
container_name: alpine-app-1
|
||||
image: alpine-app-1
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: Dockerfile
|
||||
tty: true
|
||||
ports:
|
||||
- 8081:8081
|
||||
|
||||
alpine-app-2:
|
||||
container_name: alpine-app-2
|
||||
image: alpine-app-2
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: Dockerfile
|
||||
tty: true
|
||||
ports:
|
||||
- 8080:8080
|
@ -0,0 +1,29 @@
|
||||
services:
|
||||
alpine-app-1:
|
||||
container_name: alpine-app-1
|
||||
extra_hosts: # for linux hosts since version 20.10
|
||||
- host.docker.internal:host-gateway
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: Dockerfile
|
||||
image: alpine-app-1
|
||||
tty: true
|
||||
networks:
|
||||
- first-network
|
||||
|
||||
node-app:
|
||||
container_name: node-app
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: Dockerfile.node
|
||||
image: node-app
|
||||
ports:
|
||||
- 8080:8080
|
||||
networks:
|
||||
- second-network
|
||||
|
||||
networks:
|
||||
first-network:
|
||||
driver: bridge
|
||||
second-network:
|
||||
driver: bridge
|
@ -0,0 +1,10 @@
|
||||
var express = require('express')
|
||||
var app = express()
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
res.send('Hello World!')
|
||||
})
|
||||
|
||||
app.listen(8080, function () {
|
||||
console.log('app listening on port 8080!')
|
||||
})
|
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "host_docker_internal",
|
||||
"version": "1.0.0",
|
||||
"description": "node js app",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Baeldung",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^4.18.2"
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
services:
|
||||
alpine-app-1:
|
||||
container_name: alpine-app-1
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: Dockerfile
|
||||
image: alpine-app-1
|
||||
tty: true
|
||||
ports:
|
||||
- 8080:8080
|
||||
networks:
|
||||
network-example:
|
||||
ipv4_address: 10.5.0.2
|
||||
|
||||
alpine-app-2:
|
||||
container_name: alpine-app-2
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: Dockerfile
|
||||
image: alpine-app-2
|
||||
tty: true
|
||||
ports:
|
||||
- 8081:8081
|
||||
networks:
|
||||
network-example:
|
||||
ipv4_address: 10.5.0.3
|
||||
|
||||
networks:
|
||||
network-example:
|
||||
driver: bridge
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 10.5.0.0/16
|
||||
gateway: 10.5.0.1
|
@ -0,0 +1,36 @@
|
||||
services:
|
||||
alpine-app-1:
|
||||
container_name: alpine-app-1
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: Dockerfile
|
||||
image: alpine-app-1
|
||||
tty: true
|
||||
ports:
|
||||
- 8080:8080
|
||||
networks:
|
||||
network-example:
|
||||
ipv4_address: 192.168.2.2
|
||||
|
||||
alpine-app-2:
|
||||
container_name: alpine-app-2
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: Dockerfile
|
||||
image: alpine-app-2
|
||||
tty: true
|
||||
ports:
|
||||
- 8081:8081
|
||||
networks:
|
||||
network-example:
|
||||
ipv4_address: 192.168.2.3
|
||||
|
||||
networks:
|
||||
network-example:
|
||||
driver: macvlan
|
||||
driver_opts:
|
||||
parent: enp0s3
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 192.168.2.0/24
|
||||
gateway: 192.168.2.1
|
16
docker-modules/docker-compose-2/pom.xml
Normal file
16
docker-modules/docker-compose-2/pom.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>docker-compose-2</artifactId>
|
||||
<description>Demo project for Spring Boot and Docker - Module docker-compose-2</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
</project>
|
@ -18,6 +18,7 @@
|
||||
<modules>
|
||||
<module>docker-caching</module>
|
||||
<module>docker-compose</module>
|
||||
<module>docker-compose-2</module>
|
||||
<module>docker-containers</module>
|
||||
<module>docker-images</module>
|
||||
<module>docker-spring-boot</module>
|
||||
|
Loading…
x
Reference in New Issue
Block a user