未找到错误404-在docker化并部署到服务器后,未映射的URL

如何解决未找到错误404-在docker化并部署到服务器后,未映射的URL

我有一个Kotling弹簧启动应用程序(Gradle),在本地开发环境中运行没有问题。

将代码库放入Bitbucket后,构建管道会自动运行并使用Gradlew命令生成docker映像:./gradlew clean buildDocker asciidoctor -x test;

  • 这是bitbucket-pipelines文件
# This is a sample build configuration for Docker.
# Check our guides at https://confluence.atlassian.com/x/O1toN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: atlassian/default-image:2

getProperties: &getProperties
  step:
    image: atlassian/default-image:2
    name: Properties
    script:
      # Get variables from deployment file.
      - export DEPLOYMENT_FILE_PATH=$BITBUCKET_CLONE_DIR/deployment/$BITBUCKET_BRANCH/deployment.json
      - if [ -e $DEPLOYMENT_FILE_PATH ] ; 
        then 
        VALUES="$(cat $DEPLOYMENT_FILE_PATH)";
        for s in $(echo $VALUES | jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ); 
          do
          export $s;
          echo $s >> ENVIRONMENT_VARIABLES.txt;
          done
        else
        echo "server=\"\"" >> ENVIRONMENT_VARIABLES.txt;
        echo "username=\"\"" >> ENVIRONMENT_VARIABLES.txt;
        echo "credentials=\"\"" >> ENVIRONMENT_VARIABLES.txt;
        echo "buildable=\"\"" >> ENVIRONMENT_VARIABLES.txt;
        echo "deployable=\"\"" >> ENVIRONMENT_VARIABLES.txt;
        echo "tag=\"\"" >> ENVIRONMENT_VARIABLES.txt;
        fi
      - cd <project> && echo "version="`./gradlew properties -q | grep "^version:" | awk '{printf $2}'` >> ../ENVIRONMENT_VARIABLES.txt
      - echo "name="`./gradlew properties -q | grep "name:" | awk '{printf $2}'` >> ../ENVIRONMENT_VARIABLES.txt
      - echo "documentationFolder=/data/<project>/static-server/htdocs/documentation" >> ../ENVIRONMENT_VARIABLES.txt
      - cat ../ENVIRONMENT_VARIABLES.txt
    artifacts: # defining the artifacts to be passed to each future step.
      - ENVIRONMENT_VARIABLES.txt

buildAndPushImage:  &buildPush
  step:
    name: Build / Push
    image: google/cloud-sdk:latest
    services:
      # Use service Docker to have to docker shell command 
      - docker
    caches:
      # Specify a gradle cache
      - gradle
    script:
      # Import all environment variables 
      - if [ -e $BITBUCKET_CLONE_DIR/ENVIRONMENT_VARIABLES.txt ] ;
       then 
         export $(cat ENVIRONMENT_VARIABLES.txt | xargs); 
       fi

      # BUILD
      - if [ $buildable ]; 
       then
         export BRANCH_NAME=$BITBUCKET_BRANCH;
         cd <project> && ./gradlew clean buildDocker asciidoctor -x test;
       fi
      - docker image ls

      # PUSH 
      - if [ $buildable ];
       then
        IMAGE_BUILT="noor/$name:$version-$BITBUCKET_BRANCH";
        IMAGE_NAME=$GCR_HOSTNAME/$GCR_PROJECT_ID/$BITBUCKET_REPO_SLUG;
        echo $GCR_API_KEYFILE > ~/.gcloud-api-key.json;
        gcloud auth activate-service-account --key-file ~/.gcloud-api-key.json;
        gcloud config set project $GCR_PROJECT_ID;
        gcloud auth configure-docker --quiet;
        docker image tag $IMAGE_BUILT $IMAGE_NAME:$BITBUCKET_COMMIT;
        docker image tag $IMAGE_BUILT $IMAGE_NAME:$BITBUCKET_BRANCH;
        docker push $IMAGE_NAME:$BITBUCKET_COMMIT;
        docker push $IMAGE_NAME:$BITBUCKET_BRANCH;
       fi

pullAndPushImageMaster: &pushLatest
  step:
    name: Pull / Push latest
    image: google/cloud-sdk:latest
    services:
      # Use service Docker to have to docker shell command 
      - docker
    caches:
      # Specify a gradle cache
      - gradle
    script:
      - IMAGE_NAME=$GCR_HOSTNAME/$GCR_PROJECT_ID/$BITBUCKET_REPO_SLUG;
      - echo $GCR_API_KEYFILE > ~/.gcloud-api-key.json;
      - gcloud auth activate-service-account --key-file ~/.gcloud-api-key.json;
      - gcloud config set project $GCR_PROJECT_ID;
      - gcloud auth configure-docker --quiet;
      - docker pull $IMAGE_NAME:$IMAGE_TAG_PULLED;
      - docker image tag $IMAGE_NAME:$IMAGE_TAG_PULLED $IMAGE_NAME:$IMAGE_TAG_MASTER;
      - docker push $IMAGE_NAME:$IMAGE_TAG_MASTER;


pipelines:
  custom:
    getProperties:
      - <<: *getProperties
    buildPush:  
      - <<: *buildPush

  branches:
    feature/pipeline:
      - <<: *getProperties
      - <<: *buildPush

    develop:
      - <<: *getProperties
      - <<: *buildPush

    preprod:
      - <<: *getProperties
      - <<: *buildPush

    recette:
      - <<: *getProperties
      - <<: *buildPush

    master:
      - <<: *getProperties
      - <<: *buildPush
      - <<: *pushLatest
  • 这是build.gradle项目文件
import java.text.SimpleDateFormat

buildscript {
    ext {
        kotlinVersion = '1.3.20'
        springBootVersion = '2.0.4.RELEASE'
        restEasyVersion = '3.5.1.Final'
        keyCloakVersion = '4.4.0.Final'
        sonarVersion = '2.6.2'
        snippetsDir = file('build/generated-snippets')
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
        classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
        classpath("org.asciidoctor:asciidoctor-gradle-plugin:1.5.3")
        classpath("org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16")
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:${sonarVersion}"
        classpath("org.infinispan:infinispan-core:9.4.11.Final")
    }
}
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.asciidoctor.convert'
//apply from: "$project.rootDir/tools/sonar-jacoco.gradle"

version = '0.1'
sourceCompatibility = 1.8

//keep it after version
apply from: 'gradle/docker.gradle'

asciidoctor {
    sourceDir 'src/main/asciidoc'
    outputDir 'build/docs'
    separateOutputDirs false
    attributes 'snippets': snippetsDir,"version": 1.0,"date": new SimpleDateFormat("dd-MM-yyyy").format(new Date())
    backends = ['pdf','html5']
}

compileKotlin {
    kotlinOptions {
        freeCompilerArgs = ["-Xjsr305=strict"]
        jvmTarget = "1.8"
    }
}
compileTestKotlin {
    kotlinOptions {
        freeCompilerArgs = ["-Xjsr305=strict"]
        jvmTarget = "1.8"
    }
}
configurations {
    jaxb
    ktlint
}
repositories {
    mavenCentral()
    jcenter()
}

test {
    forkEvery = 1
    filter {
        includeTestsMatching System.getProperty("includeTests","**")
    }
    reports {
        html.enabled = true
    }
}
// MARK[AMABIS REMOVAL] - START
/*task genJaxb {
    ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
    ext.classesDir = "${buildDir}/classes/jaxb"
    ext.schema = "http://sw1.amabis.ma:5200?wsdl"

    outputs.dir classesDir

    doLast() {
        project.ant {
            taskdef name: "xjc",classname: "com.sun.tools.xjc.XJCTask",classpath: configurations.jaxb.asPath
            mkdir(dir: sourcesDir)
            mkdir(dir: classesDir)

            xjc(destdir: sourcesDir,schema: schema,package: "amabis.wsdl") {
                arg(value: "-wsdl")
                produces(dir: sourcesDir,includes: "**//*.java")
            }

            javac(destdir: classesDir,source: 1.8,target: 1.8,debug: true,debugLevel: "lines,vars,source",classpath: configurations.jaxb.asPath) {
                src(path: sourcesDir)
                include(name: "**//*.java")
                include(name: "*.java")
            }

            copy(todir: classesDir) {
                fileset(dir: sourcesDir,erroronmissingdir: false) {
                    exclude(name: "**//*.java")
                }
            }
        }
    }
}*/
// MARK[AMABIS REMOVAL] - END
dependencies {
    //Spring Boot
    compile('org.springframework.boot:spring-boot-starter-cache')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile group: 'org.springframework.boot',name: 'spring-boot-starter-mail',version: '2.0.2.RELEASE'
    compile group: 'org.springframework',name: 'spring-context-support',version: '5.0.6.RELEASE'
    compile("org.springframework.ws:spring-ws-core")
    compile('org.springframework.boot:spring-boot-starter-web') {
        exclude module: 'spring-boot-starter-tomcat'
    }
    
    compile('org.springframework:spring-aop:5.0.1.RELEASE')
    compile('org.aspectj:aspectjweaver:1.8.12')
    compile "org.springframework.boot:spring-boot-starter-undertow"
    compile "org.springframework.boot:spring-boot-starter-actuator"

    compile group: 'org.springframework.boot',name: 'spring-boot-starter-thymeleaf',version: '2.0.2.RELEASE'

    // Kotlin
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'

    //Swagger
    implementation("io.springfox:springfox-swagger-ui:2.9.2")
    compile group: 'io.springfox',name: 'springfox-swagger-common',version: '2.9.2'
    compile group: 'io.springfox',name: 'springfox-core',name: 'springfox-swagger2',name: 'springfox-bean-validators',version: '2.9.2'

    implementation 'com.opencsv:opencsv:5.0'

    //Cache
    compile group: 'org.infinispan',name: 'infinispan-spring-boot-starter-embedded',version: '2.1.0.Final'

    //Keycloak
    compile group: 'org.keycloak',name: 'keycloak-spring-security-adapter',version: keyCloakVersion
    compile group: 'org.keycloak',name: 'keycloak-authz-client',name: 'keycloak-admin-client',version: keyCloakVersion
    compile group: 'org.jboss.resteasy',name: 'resteasy-client',version: restEasyVersion
    compile group: 'org.jboss.resteasy',name: 'resteasy-jaxrs',name: 'resteasy-jackson2-provider',name: 'resteasy-spring',version: restEasyVersion

    // PDF
    // https://mvnrepository.com/artifact/com.lowagie/itext
    // https://mvnrepository.com/artifact/org.xhtmlrenderer/flying-saucer-core
    compile group: 'org.xhtmlrenderer',name: 'flying-saucer-core',version: '9.1.16'
    // https://mvnrepository.com/artifact/org.xhtmlrenderer/flying-saucer-pdf
    compile group: 'org.xhtmlrenderer',name: 'flying-saucer-pdf',version: '9.1.16'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf
    compile group: 'org.springframework.boot',version: springBootVersion
    // https://mvnrepository.com/artifact/org.springframework.retry/spring-retry
    compile group: 'org.springframework.retry',name: 'spring-retry',version: '1.2.4.RELEASE'
    compile('org.springframework:spring-aspects')


    //Minio server
    compile 'io.minio:minio:6.0.11'

    //JaxB
    // MARK[AMABIS REMOVAL] - START

    /*compile(files(genJaxb.classesDir).builtBy(genJaxb))
    compile group: 'com.sun.xml.bind',name: 'jaxb-impl',version: '2.2.11'
    compile group: 'com.sun.xml.bind',name: 'jaxb-core',version: '2.2.11'
    compile group: 'javax.xml.bind',name: 'jaxb-api',version: '2.2.11'
    compile group: 'javax.xml.ws',name: 'jaxws-api',version: '2.2.11'
    compile group: 'javax.xml.soap',name: 'javax.xml.soap-api',version: '1.4.0'
    compile group: 'javax.activation',name: 'activation',version: '1.1.1'

    jaxb 'com.sun.xml.bind:jaxb-core:2.2.11'
    jaxb 'com.sun.xml.bind:jaxb-impl:2.2.11'
    jaxb "com.sun.xml.bind:jaxb-xjc:2.2.11"*/

    // MARK[AMABIS REMOVAL] - END


    //Jsonb api (need for resteasy client)
    compile group: 'org.apache.geronimo.specs',name: 'geronimo-json_1.1_spec',version: '1.0'
    compile group: 'org.apache.johnzon',name: 'johnzon-jsonb',version: '1.1.7'

    //Jolt
    compile group: 'com.bazaarvoice.jolt',name: 'jolt-core',version: '0.1.1'
    compile group: 'com.bazaarvoice.jolt',name: 'json-utils',version: '0.1.1'

    //Kotlin
    compile('com.fasterxml.jackson.module:jackson-module-kotlin')
    compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    compile("org.jetbrains.kotlin:kotlin-reflect")

    //Utils
    compile group: 'org.apache.commons',name: 'commons-lang3',version: '3.7'
    compile group: 'com.fasterxml.jackson.datatype',name: 'jackson-datatype-jsr310',version: '2.9.6'

    // Facebook
    // https://developers.facebook.com/docs/apis-and-sdks
    compile group: 'com.restfb',name: 'restfb',version: '2.6.0'
    compile 'com.google.api-client:google-api-client:1.30.9'
    compile group: 'com.google.apis',name: 'google-api-services-oauth2',version: 'v2-rev157-1.25.0'
    // https://mvnrepository.com/artifact/org.bitbucket.b_c/jose4j
    compile group: 'org.bitbucket.b_c',name: 'jose4j',version: '0.7.2'


    // Schedule
    compile "org.springframework.boot:spring-boot-starter-quartz"
    // If used with external database
    compile "org.springframework.boot:spring-boot-starter-jdbc"
    // https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client
    compile group: 'org.mariadb.jdbc',name: 'mariadb-java-client',version: '2.2.5'

    // Logback Json support
    compile "ch.qos.logback.contrib:logback-json-classic:0.1.5"
    compile "ch.qos.logback.contrib:logback-jackson:0.1.5"
    compile "net.logstash.logback:logstash-logback-encoder:5.1"

    compile group: 'com.h2database',name: 'h2',version: '1.4.197'

    // https://mvnrepository.com/artifact/org.apache.tika/tika-core
    compile group: 'org.apache.tika',name: 'tika-core',version: '1.20'

    //Test
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.springframework.security:spring-security-test')
    testCompile "org.mockito:mockito-core"

    //testCompile "com.github.tomakehurst:wiremock:2.18.0"
    testCompile group: 'org.springframework.restdocs',name: 'spring-restdocs-mockmvc',version: '2.0.2.RELEASE'

    testCompile group: 'org.mock-server',name: 'mockserver-netty',version: '5.4.1'

    testCompile group: 'com.squareup.okhttp',name: 'mockwebserver',version: '2.7.5'

    // https://mvnrepository.com/artifact/com.icegreen/greenmail
    testCompile group: 'com.icegreen',name: 'greenmail',version: '1.5.7'

    ktlint "com.github.shyiko:ktlint:0.29.0"
}

/**
 * Setups taks
 */
apply from: rootProject.file('gradle/setup/setup.gradle')

/**
 * KLINT
 */
task ktlint(type: JavaExec,group: "verification") {
    description = "Check Kotlin code style."
    classpath = configurations.ktlint
    main = "com.github.shyiko.ktlint.Main"
    args "src/**/*.kt"
    // to generate report in checkstyle format prepend following args:
    // "--reporter=plain","--reporter=checkstyle,output=${buildDir}/ktlint.xml"
    // see https://github.com/shyiko/ktlint#usage for more
}
check.dependsOn ktlint

task ktlintFormat(type: JavaExec,group: "formatting") {
    description = "Fix Kotlin code style deviations."
    classpath = configurations.ktlint
    main = "com.github.shyiko.ktlint.Main"
    args "-F","src/**/*.kt"
}

此构建管道始终具有相同的构建成功日志模板(管道构建没有问题)

构建完成后,我们运行docker compose命令将Docker容器部署到服务器中: docker-compose pull && docker-compose up -d

一旦完成部署,在尝试到达某些端点(springfox和某些其他端点)时,我会随机出现404错误(找不到页面)。

要解决此问题,我只需重新运行构建管道并重新部署应用程序,它便可以正常工作。

请帮助解决此问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-