新来的,想知道是否有人有以非 root 用户身份构建映像的经验?
我正在构建 Kotlin 项目(两步构建),我现在的目标是以非 root 用户身份构建它。这是我的 Dockerfile 的样子。任何帮助,将不胜感激:
# Build
FROM openjdk:11-jdk-slim as builder
# Compile application
WORKDIR /root
COPY . .
RUN ./gradlew build
FROM openjdk:11-jre-slim
# Add application
COPY --from=builder /root/build/libs/*.jar ./app.jar
# Set the build version
ARG build_version
ENV BUILD_VERSION=$build_version
COPY docker-entrypoint.sh /
RUN chmod 777 /docker-entrypoint.sh
CMD /docker-entrypoint.sh
Run Code Online (Sandbox Code Playgroud) 在我的doctrine.php我有以下配置
<?php
// See https://symfony.com/doc/current/reference/configuration/framework.html
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
return static function (ContainerConfigurator $container) {
$container->extension('doctrine', [
'dbal' => [
'url' => '%env(DATABASE_URL)%',
],
'orm' => [
'auto_generate_proxy_classes' => true,
'auto_mapping' => true,
'mappings' => [
'default' => [
'is_bundle' => false,
'type' => 'annotation',
'dir' => '%kernel.project_dir%/src/Entity',
'prefix' => 'App\Entity',
'alias' => 'App'
]
]
]
]);
};
Run Code Online (Sandbox Code Playgroud)
我的实体类定义如下
namespace App\Entity;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Table;
#[Entity(repositoryClass: EntityRepository::class)]
#[Table(name: 'entity')]
class Entity
...
Run Code Online (Sandbox Code Playgroud)
getRepository我尝试通过这样的调用来访问它
$entityRepository = $entityManager->getRepository(Entity::class);
Run Code Online (Sandbox Code Playgroud)
但这失败了is …