{"id":20138689,"url":"https://github.com/el-moudni-hicham/deploy-springboot-microservices-docker","last_synced_at":"2026-05-08T03:03:51.053Z","repository":{"id":209726980,"uuid":"724805073","full_name":"el-moudni-hicham/deploy-springboot-microservices-docker","owner":"el-moudni-hicham","description":"Build and Deploy Spring Boot Microservices using Docker (Dockerfile, docker-compose files)","archived":false,"fork":false,"pushed_at":"2023-11-28T20:55:48.000Z","size":79,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-13T10:09:26.113Z","etag":null,"topics":["deployment","devops","docker","microservices","springboot"],"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/el-moudni-hicham.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-28T20:37:43.000Z","updated_at":"2023-11-28T20:41:21.000Z","dependencies_parsed_at":"2024-01-30T16:17:13.372Z","dependency_job_id":null,"html_url":"https://github.com/el-moudni-hicham/deploy-springboot-microservices-docker","commit_stats":null,"previous_names":["el-moudni-hicham/deploy-springboot-microservices-docker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/el-moudni-hicham%2Fdeploy-springboot-microservices-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/el-moudni-hicham%2Fdeploy-springboot-microservices-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/el-moudni-hicham%2Fdeploy-springboot-microservices-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/el-moudni-hicham%2Fdeploy-springboot-microservices-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/el-moudni-hicham","download_url":"https://codeload.github.com/el-moudni-hicham/deploy-springboot-microservices-docker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241582554,"owners_count":19985846,"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","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":["deployment","devops","docker","microservices","springboot"],"created_at":"2024-11-13T21:40:30.487Z","updated_at":"2026-05-08T03:03:50.980Z","avatar_url":"https://github.com/el-moudni-hicham.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Build and Deploy Spring Boot Microservices using Docker\n\n**IMAGE**\n\nOur image will be based on the JDK image.\n\n```python\nFROM openjdk:17-oracle\n```\n\n**VOLUME**\n\nTake example of a database running in a container. It is important to note that if we delete the container, all the data will be lost. To prevent this, we specify a data folder, in this case, \"/tmp\".\n\n```python\nVOLUME /tmp\n```\n\n**Generate JAR**\n\n```python\nmvn compile\nmvn test \nmvn package\n==\nmvn clean package -DskipTests\n```\n\nJenkins will do this work (this commands) for us after  🙂\n\n**Run JAR**\n\n```python\nCOPY target/discovery-service-0.0.1-SNAPSHOT.jar app.jar\n#COPY target/*.jar app.jar\nENTRYPOINT [\"java\", \"-jar\", \"app.jar\"]\n```\n\n**Create image** \n\n```python\ndocker images\n#if file_name = Dockerfile we put . else file_name\ndocker build . -t discovery-service:version1 \n```\n\n**Run Container** \n\n```python\n#we can also put id \"687d1ebc0bf5\" instead of name \"discovery-service\"\ndocker run discovery-service:version1\n```\n\n**Stop container**\n\n```python\n#we can just put 2 or 3 chars 787d because id is unique\ndocker stop 687d1ebc0bf5\n```\n\n```python\n#dispaly container logs\ndocker logs 687d1ebc0bf5\n```\n\n**Display Containers** \n\n```python\ndocker ps \n```\n\n**Expose our container in externe**\n\nmake it accessible \n\n```python\ndocker run -p 8761:8761 discovery-service:version1\n# -p port_in_externe : port_in_container\n```\n\n```python\n#to run container in background not appear in console\ndocker run -d -p 8761:8761 discovery-service:version1\n```\n\n**Docker Compose**\n\nNow we don’t need to use all past methods\n\n```yaml\nservices:\n  ebank-discovery-service:\n    build: ./discovery-service                  #go to this folder to find Dockerfile\n    container_name: ebank-discovery-service\n    ports:\n      - '8761:8761'\n    expose:\n      - '8761'\n    healthcheck:\n      #curl to send an http request to check app health\n      #-f if we have a fail return fail status code\n      test: ['CMD', 'curl', '-f', 'http://localhost:8761/actuator/health']\n      #each 10s we send request default = 30s\n      interval: 10s\n      #repeat 5 times\n      retries: 5\n```\n\n```python\ndocker compose up\n#start container in background\ndocker compose up -d \n#if we not use --build docker will not generate an image if it already exist\ndocker compose up -d --build\n```\n\n**Destroy container**\n\nthis is why we use VOLUME to save data out of container\n\n```python\ndocker compose down\n```\n\n```yaml\nebank-config-service:\n    build: ./config-service\n    container_name: ebank-config-service\n    ports:\n      - '9999:9999'\n    expose:\n      - '9999'\n    environment:\n      #we specify the url of ebank-discovery-service\n      #we use this variable because if we use localhost docker search in it's own localhost\n      - DISCOVERY_SERVICE_URL=http://ebank-discovery-service:8761/eureka\n    depends_on:\n      ebank-discovery-service:\n        condition: service_healthy\n```\n\nlifecycle : Created → Waiting → Healthy → Started\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fel-moudni-hicham%2Fdeploy-springboot-microservices-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fel-moudni-hicham%2Fdeploy-springboot-microservices-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fel-moudni-hicham%2Fdeploy-springboot-microservices-docker/lists"}