{"id":30754260,"url":"https://github.com/twogg-git/docker-compose-java","last_synced_at":"2025-09-04T09:08:56.059Z","repository":{"id":19436399,"uuid":"87032529","full_name":"twogg-git/docker-compose-java","owner":"twogg-git","description":"A bit more complex docker-compose example with Java, Tomcat, PostgreSQL and a SMTP.","archived":false,"fork":false,"pushed_at":"2023-04-17T17:35:16.000Z","size":17928,"stargazers_count":14,"open_issues_count":2,"forks_count":11,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T02:01:52.827Z","etag":null,"topics":["docker-compose","java","postgres","rest","smtp","smtp-server","tomcat"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twogg-git.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-03T02:42:52.000Z","updated_at":"2023-10-16T10:29:54.000Z","dependencies_parsed_at":"2022-09-17T20:50:27.656Z","dependency_job_id":null,"html_url":"https://github.com/twogg-git/docker-compose-java","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/twogg-git/docker-compose-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twogg-git%2Fdocker-compose-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twogg-git%2Fdocker-compose-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twogg-git%2Fdocker-compose-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twogg-git%2Fdocker-compose-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twogg-git","download_url":"https://codeload.github.com/twogg-git/docker-compose-java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twogg-git%2Fdocker-compose-java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273581238,"owners_count":25131393,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker-compose","java","postgres","rest","smtp","smtp-server","tomcat"],"created_at":"2025-09-04T09:07:47.045Z","updated_at":"2025-09-04T09:08:56.051Z","avatar_url":"https://github.com/twogg-git.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"![deploying-docker-compose](rsc/docker-compose.png)\n\n## Advance use of Docker-Compose\n\nThis Docker-Compose example will let you send emails thanks to a REST service provided by a *JAVA* web application running over a *Tomcat* server and logging the emails sent on a *Postgres* database. All three containers deployed separately thanks to Docker-Compose. \n\n![deploying-docker-compose-tomcat](rsc/tomcat.jpg)\n#### Webapp Container: Java \u0026 Tomcat\n\nTo build each container on their folders we use *build* tag. First folder to search a Dockerfile and build it will be 'server', in that Dockerfile we are going to pull an image with Tomcat and Java JDK ready.\n\n```sh\nFROM tomcat:8-jre8\n```\n\nThen for deploying JAVA application we copy the .war file inside Tomcat's webapps folder. \n\n```sh\nCOPY /webapp/emailboot.war /usr/local/tomcat/webapps/ROOT.war\n```\n\nFinally it will build *db* and *smtp* containers.  \n \n```sh\n web:\n   build: server\n   ports:\n     - \"8080:8080\"\n   links:\n     - db\n     - smtp\n```\n![deploying-docker-compose-tomcat](rsc/postgresql.jpg)\n#### Database Container: Postgres\n\nFor the database container we include emailboot.sql initial script.\n\n```sh\nCREATE TABLE IF NOT EXISTS email_logger (\n  log_id            SERIAL                      NOT NULL,\n  log_serial        VARCHAR(100)                NOT NULL,\n  log_subject       VARCHAR(100)                NOT NULL,\n  log_delivered     BOOL                        NOT NULL DEFAULT 'false',\n  log_content       VARCHAR(2500)               NOT NULL,\n  log_timestamp     TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT current_timestamp\n) WITH (OIDS =FALSE);\nALTER TABLE email_logger OWNER TO emailboot;\n```\n\nIt will we run on Postgres start thanks to this command in the Dockerfile.\n\n```sh\nADD script/emailboot.sql /docker-entrypoint-initdb.d/\n```\n\nTo setup properties and ports we are going to use Docker-Compose as is follows:\n \n```sh\ndb:\n  build: database\n  restart: always\n  ports:\n      - \"5432:5432\"\n  environment:\n      - DEBUG=true\n      - POSTGRES_USER=testusr\n      - POSTGRES_PASSWORD=testpwd\n```\n![deploying-docker-compose-tomcat](rsc/smtp.jpg)      \n#### SMTP Container: Postfix \n\nFinally we add a simple Postfix SMTP TLS relay docker image with no local authentication enabled (to be run in a secure LAN). To setup properties and ports we are going to use Docker-Compose as is follows:\n\n```sh\nsmtp:\n  build: smtp\n  ports:\n    - \"25:25\"\n  environment:\n    - maildomain=mailboot.net\n    - smtp_user=user:pwd\n    - messageSizeLimit=40960000\n    - mailboxSizeLimit=40960000\n```\n\nOriginal Image: [SMTP catatnight/postfix/](https://hub.docker.com/r/catatnight/postfix/)\n\n#### Testing REST services\n\n#### Initial test service\n\nOnce the docker-compose up command is finished you can test the webapp by accessing:\n```sh\nhttp://localhost:8080/test\n  ```\n\nIf it was deployed correctly the output should be like this:\n```sh\nEmailBoot Rest Service - Test Succeeded! \n```\n\n#### Send an email\n\nOnce the docker-compose up command is finished you can test the webapp by accessing:\n```sh\nPOST rest service\n    http://localhost:8080/v1/emails\n\nParameters\n    \"subject\" Suject of the email, it will be used on email inbox. Example: Hello I'm here!\n    \"content\" Text content, please do not add javascript in this filed, mailboxs validate javascript conent and they will reject the email. \n    \"recipients\" List of emails addresses to send the email, if they are more that one separate them with ';'. Example: test@mail.com; test2@mail.com;.\n  ```\n\nIf the request was process correctly the output should be like this:\n```sh\n{\n  \"code\": 202,\n  \"status\": \"ACCEPTED\",\n  \"url\": \"[POST] http://localhost:8080/v1/emails?subject=Subject%20test\u0026content=Testing%20content%20on%20email\u0026recipients=mail@mail.com;\",\n  \"message\": \"Email task was accepted and sent to SMTP\",\n  \"data\": {\n    \"serial\": 1491218659389,\n    \"from\": \"127.0.0.1\",\n    \"mailsList\": \"test@mail.com;\",\n    \"subject\": \"Subject test\",\n    \"content\": \"Testing content on email\",\n    \"warnings\": null,\n    \"malformedDirectEmails\": null\n  }\n} \n```\n\n#### List of emails logged\n\nAnother REST service include in the JAVA app is list all delivered emails\n```sh\nGET rest service\n    http://localhost:8080/v1/logger?startDate=\u0026endDate=2017-12-01 00:00\u0026onlyDelivered=false\n\nParameters\n    \"startDate\" Initial date to search. Example: 2017-01-01 00:00\n    \"endDate\" Final date to search. Example: 2017-12-01 00:00\n    \"onlyDelivered\" It will filter the results by only deliverd emails. Example: false *To return all emails on log.\n  ```\n\nThis is the expected output:\n\n```sh\n{\n  \"code\": 200,\n  \"status\": \"OK\",\n  \"url\": \"[GET] http://localhost:8080/v1/logger?startDate=2017-01-01%2000:00\u0026endDate=2017-12-01%2000:00\u0026onlyDelivered=false\",\n  \"message\": \"EmailBoot request response.\",\n  \"data\": [\n    {\n      \"serial\": \"1491359400489\",\n      \"subject\": \"Hello EmailBoot\",\n      \"delivered\": true,\n      \"content\": \"Working as a charm!\",\n      \"versionDate\": \"04/03/2017 05:08:51\"\n    }\n  ]\n}\n```\n\n#### List of emails logged by Serial or Subject\n\nSearch REST services included: By Serial or Subject. Filter by subject will return all the emails that contains the keywords sent.\n \n```sh\nGET rest services\n    http://localhost:8080/v1/logger/suject/Docker Test\n    http://localhost:8080/v1/logger/serial/1491359396709\n\nParameters\n    \"subject\" Text to filter by. Example: Docker Test\n    \"serial\" Generated id to filter by. Example: 1491359396709\n  ```\n\nThis is the expected output:\n\n```sh\n{\n  \"code\": 200,\n  \"status\": \"OK\",\n  \"url\": \"[GET] http://localhost:8080/v1/logger/subject/Docker%20Test\",\n  \"message\": \"EmailBoot request response.\",\n  \"data\": [\n    {\n      \"serial\": \"1491359396709\",\n      \"subject\": \"Docker Test\",\n      \"delivered\": true,\n      \"content\": \"Email build and send to SMTP\",\n      \"versionDate\": \"04/05/2017 02:29:56\"\n    },\n    {\n      \"serial\": \"1491359400486\",\n      \"subject\": \"Docker Test 1\",\n      \"delivered\": true,\n      \"content\": \"Email build and send to SMTP\",\n      \"versionDate\": \"04/05/2017 02:30:00\"\n    },\n    {\n      \"serial\": \"1491359403198\",\n      \"subject\": \"Docker Test 2\",\n      \"delivered\": true,\n      \"content\": \"Email build and send to SMTP\",\n      \"versionDate\": \"04/05/2017 02:30:03\"\n    }\n  ]\n}\n```\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwogg-git%2Fdocker-compose-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwogg-git%2Fdocker-compose-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwogg-git%2Fdocker-compose-java/lists"}