---
# System prepended metadata

title: SQ06A

---

> [name=Lucas]
> [time=Mon, May 22, 2023 11:36 AM]
> [name=Lukas]
> [time=Mon, May 22, 2023 11:36 AM] [color=#db4eae]



# SQ06A


### dockerfile für mosquitto

```dockerfile
FROM eclipse-mosquitto:latest

COPY mosquitto.conf /mosquitto/config/mosquitto.conf
EXPOSE 1883

CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"]

```

#### dazu das config für mosquitto
```mosquitto.conf
listener 1883
allow_anonymous true
```

#### Build Befehl:
```bash
docker build -t mosquitto .  
```

#### Run Befehl:
```bash
docker run -d --net=m324-net --ip=172.21.0.22 -p 1887:1887 mosquitto 
```

### dockerfile für die Sensor App

```dockerfile
FROM openjdk:18

WORKDIR /app
COPY M321-APP.jar .

CMD ["java", "-jar", "M321-APP.jar", "publisher3", "java3", "feedback/java3"]
```
#### Build Befehl:
```bash
docker build -t app .
```
#### Run Befehl:
```bash
docker run -d --net=321_dockerizing_m324-net --ip=172.21.0.21 app   
```

---

# Docker Compose File und Komponente
```docker-compose.yml
version: '3'
services:
  mosquitto:
    image: eclipse-mosquitto:latest
    volumes:
      - ./mosquitto.conf:/mosquitto/config/mosquitto.conf
    networks:
      m324-net:
        ipv4_address: 172.21.0.22
    ports:
      - "1887:1883"

  sensor-app:
    build:
      context: ./app
      dockerfile: Dockerfile
    networks:
      m324-net:
        ipv4_address: 172.21.0.21

networks:
  m324-net:
    driver: bridge
    ipam:
      config:
        - subnet: 172.21.0.0/16
```

## File Struktur


<img src="https://hackmd.io/_uploads/BkvicJFHh.png" style="margin:2vh; filter:drop-shadow(0px 0px 5px black);">



### Inhalt /app/dockerfile/
```dockerfile
FROM openjdk:18

WORKDIR /app
COPY M321-APP.jar .

CMD ["java", "-jar", "M321-APP.jar", "publisher3", "java3", "feedback/java3", "&&", "java", "-jar", "M321-APP.jar", "publisher2", "java2", "feedback/java2"]
```

### Inhalt mosquitto.conf
```dockerfile
listener 1883
allow_anonymous true
```
---
## Starten des Stacks:
```bash
docker compose up
```

<img src="https://hackmd.io/_uploads/BylJjyYH3.png" style="margin:2vh; filter:drop-shadow(0px 0px 5px black);">

<img src="https://hackmd.io/_uploads/rJfXhyYHn.png" style="margin:2vh; filter:drop-shadow(0px 0px 5px black);">




---


###### Run befehl für den Docker Container um zusätzliche sensoren zu starten:
```bash
java -jar M321-APP.jar publisher2 java2 feedback/java2
```
