Migrate to Containers CLI 可讓您將 Linux 應用程式遷移至容器化環境。它使用預先建構的 Linux 系統容器,做為現代化應用程式所需服務的系統啟動載入程式。使用 Linux 應用程式的 Migrate to Containers,您可以翻新各種無狀態應用程式,在 Google Kubernetes Engine (GKE)、Cloud Run 和 GKE 叢集中執行。
Migrate to Containers 會探索來源應用程式檔案和程序。接著產生構件,包括 Dockerfile、Kubernetes 資訊清單和 Skaffold 設定。
Linux 系統容器的主要功能,是啟動原本在來源虛擬機器 (VM) 執行個體上執行的服務,包括相關作業系統和應用程式服務。
Dockerfile 可用來為遷移的 VM 建構映像檔。Linux 系統容器 Dockerfile 通常如下所示:
# 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/"]
執行遷移作業時,下列 Dockerfile 陳述式會將 VM 資料從原始來源複製或新增至 Docker 映像檔:
下列陳述式會將含有從來源 VM 擷取的資料的 tar 檔案新增至 Docker 映像檔:
ADD vmFiles.tar.gz /
這個 tar 檔案是由 Migrate to Containers 建立。其中包含來源 VM 的根檔案系統,以及遷移計畫中篩選器提供的所有項目,以及資料遷移計畫中提供的任何資料夾。
下列陳述式會將「遷移至容器」執行階段從 Docker 存放區匯入至 Docker 映像檔:
FROM us-docker.pkg.dev/migrate-modernize-public/modernize-plugins-prod/service-manager-runtime:1.0.0 as service-manager-runtime
接著,下列陳述式會將「Migrate to Containers」執行階段複製到 Docker 映像檔:
COPY --from=service-manager-runtime / /
按一下這裡,查看 Migrate to Containers 執行階段檔案的詳細資料
/ko-app/service-manager-runtime 是主要的 Migrate to Containers 執行階段檔案。這是專為容器打造的初始化系統。這個檔案可執行以下作業:
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],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."]]