借助 Migrate to Containers CLI,您可以将基于 Linux 的应用迁移到容器化环境。它使用预构建的 Linux 系统容器充当现代化应用所需服务的引导加载程序。借助 Migrate to Containers for Linux 应用,您可以对各种无状态应用进行现代化改造,以便在 Google Kubernetes Engine (GKE)、Cloud Run 和 GKE 集群上运行。
# Please refer to the documentation:
# https://cloud.google.com/migrate/anthos/docs/dockerfile-reference
FROM us-docker.pkg.dev/migrate-modernize-public/modernize-plugins-prod/service-manager-runtime:1.0.0 as service-manager-runtime
FROM scratch
# Tar containing data captured from the source VM
ADD vmFiles.tar.gz /
COPY --from=service-manager-runtime / /
ADD blocklist.yaml /.m4a/blocklist.yaml
ADD logs.yaml /code/config/logs/logsArtifact.yaml
ADD services-config.yaml /.m4a/
ADD tempfiles.yaml /.m4a/
# If you want to update parts of the image, add your commands here.
# For example:
# RUN apt-get update
# RUN apt-get install -y \
# package1=version \
# package2=version \
# package3=version
# RUN yum update
# RUN wget http://github.com
ENTRYPOINT ["/ko-app/service-manager-runtime", "start", "-c", "/.m4a/"]
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-19。"],[],[],null,["# About Linux system containers\n=============================\n\nThe Migrate to Containers CLI lets you migrate Linux-based applications to\ncontainerized environments. It uses a prebuilt Linux system container that\nfunctions as a bootloader for the services required by the modernized\napplication. Using Migrate to Containers for Linux applications, you can modernize a\nwide range of stateless applications to run on Google Kubernetes Engine (GKE),\nCloud Run, and GKE clusters.\n\nFor more information, see [Migrate to Containers CLI architecture](/migrate/containers/docs/m2c-cli/architecture).\n\nThis document provides details about Migrate to Containers Linux system containers\nthat are used as a part of the solution for running applications migrated using\nMigrate to Containers.\n\nMigration using Linux system container\n--------------------------------------\n\nMigrate to Containers discovers the source application files and processes. It then\ngenerates artifacts which include a Dockerfile, Kubernetes manifest, and\nSkaffold configuration.\n\nThe main function of a Linux system container is to initiate the services that\nwere originally run at the source virtual machine (VM) instance, including\nrelevant operating system and application services.\n\nThe Dockerfile is used to build the image for your migrated VM. A Linux system\ncontainer Dockerfile usually looks similar to the following: \n\n # Please refer to the documentation:\n # https://cloud.google.com/migrate/anthos/docs/dockerfile-reference\n\n FROM us-docker.pkg.dev/migrate-modernize-public/modernize-plugins-prod/service-manager-runtime:1.0.0 as service-manager-runtime\n\n FROM scratch\n\n # Tar containing data captured from the source VM\n ADD vmFiles.tar.gz /\n\n COPY --from=service-manager-runtime / /\n\n ADD blocklist.yaml /.m4a/blocklist.yaml\n\n ADD logs.yaml /code/config/logs/logsArtifact.yaml\n\n ADD services-config.yaml /.m4a/\n\n ADD tempfiles.yaml /.m4a/\n\n # If you want to update parts of the image, add your commands here.\n # For example:\n # RUN apt-get update\n # RUN apt-get install -y \\\n # package1=version \\\n # package2=version \\\n # package3=version\n # RUN yum update\n # RUN wget http://github.com\n\n ENTRYPOINT [\"/ko-app/service-manager-runtime\", \"start\", \"-c\", \"/.m4a/\"]\n\nWhen you execute a migration, the following Dockerfile statements copy or add\nthe VM data from the original source to the Docker image:\n\n- The following statement adds the tar file that contains the data captured\n from the source VM to the Docker image:\n\n ADD vmFiles.tar.gz /\n\n This tar is created by Migrate to Containers. It contains the root file system of\n the source VM with everything provided in filters in the migration plan and\n any folder provided in the data migration plan filtered out.\n- The following statement imports the Migrate to Containers runtime from the Docker\n repository into the Docker image:\n\n FROM us-docker.pkg.dev/migrate-modernize-public/modernize-plugins-prod/service-manager-runtime:1.0.0 as service-manager-runtime\n\n- The following statement then copies the Migrate to Containers runtime into the\n Docker image:\n\n COPY --from=service-manager-runtime / /\n\n#### Click to view details about the Migrate to Containers runtime file\n\n`/ko-app/service-manager-runtime` is the main Migrate to Containers\nruntime file. This is an initialization system that is made for containers. It\ndoes the following:\n\n- Reads the `/.m4a/services-config.yaml` file, and runs the specified binaries in order according to the specified run method such as daemonize, not daemonize, wait for finish.\n- Collects logs specified in the `/code/config/logs/logsArtifact.yaml` file and prints them to `stdout` of the container. For GKE and GKE clusters, it also ensures that the logs are sent to Cloud Logging.\n\nMaintenance of migrated workloads\n---------------------------------\n\nYou can create a new pipeline for your application from the migrated artifacts.\nYou might have a different pipeline for different applications. You can keep\nyour existing continuous integration and deployment pipeline which\ngenerated the original VM-based application, and add the relevant steps that\ntransform the generated executables into Linux system containers.\n\nThe following diagram illustrates a sample pipeline using Migrate to Containers:\n\nThis diagram shows the change process of an existing application.\n\nA change to source code or new OS path is pushed to the existing Git\nrepository. The source is compiled based on the existing setup and a new image\nis built. The new image includes the Migrate to Containers runtime layer.\n\nIn the test environment, a developer runs preliminary tests to confirm\nwhether the new image is working as expected. After the test phase, a new\nsystem container image is created and pushed to the development or test\nenvironment, which is later rolled out to production."]]