Sesuaikan sampel 'Publikasikan gambar Docker ke ECR Amazon' untuk mendorong ke Docker Hub - AWS CodeBuild

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Sesuaikan sampel 'Publikasikan gambar Docker ke ECR Amazon' untuk mendorong ke Docker Hub

Untuk mengadaptasi sampel 'Publikasikan gambar Docker ke ECR Amazon' sehingga gambar Docker didorong ke Docker Hub alih-alih AmazonECR, edit kode sampel. Untuk informasi lebih lanjut tentang sampel, lihat Contoh 'Publikasikan gambar Docker ke repositori ECR gambar Amazon' untuk CodeBuild danJalankan sampel 'Publikasikan gambar Docker ke ECR Amazon'.

catatan

Jika Anda menggunakan versi Docker lebih awal dari 17.06, hapus opsi. --no-include-email

  1. Ganti baris ECR kode khusus Amazon ini dalam buildspec.yml file:

    ... pre_build: commands: - echo Logging in to Amazon ECR... - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com build: commands: - echo Build started on `date` - echo Building the Docker image... - docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG . - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG post_build: commands: - echo Build completed on `date` - echo Pushing the Docker image... - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG ...

    Dengan baris kode khusus Docker Hub ini:

    ... pre_build: commands: - echo Logging in to Docker Hub... # Type the command to log in to your Docker Hub account here. build: commands: - echo Build started on `date` - echo Building the Docker image... - docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG . - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $IMAGE_REPO_NAME:$IMAGE_TAG post_build: commands: - echo Build completed on `date` - echo Pushing the Docker image... - docker push $IMAGE_REPO_NAME:$IMAGE_TAG ...
  2. Unggah kode yang diedit ke bucket input S3 atau repositori AWS CodeCommit, GitHub, atau Bitbucket.

    penting

    Jangan mengunggah(root directory name), hanya file di dalamnya(root directory name).

    Jika Anda menggunakan bucket input S3, pastikan untuk membuat ZIP file yang berisi file, lalu unggah ke bucket input. Jangan tambahkan (root directory name) ke ZIP file, hanya file di dalamnya(root directory name).

  3. Ganti baris kode ini dari input JSON yang diformat ke perintah: create-project

    ... "environmentVariables": [ { "name": "AWS_DEFAULT_REGION", "value": "region-ID" }, { "name": "AWS_ACCOUNT_ID", "value": "account-ID" }, { "name": "IMAGE_REPO_NAME", "value": "Amazon-ECR-repo-name" }, { "name": "IMAGE_TAG", "value": "latest" } ] ...

    Dengan baris kode ini:

    ... "environmentVariables": [ { "name": "IMAGE_REPO_NAME", "value": "your-Docker-Hub-repo-name" }, { "name": "IMAGE_TAG", "value": "latest" } ] ...
  4. Buat lingkungan build, jalankan build, dan lihat informasi build terkait.

  5. Konfirmasikan bahwa AWS CodeBuild berhasil mendorong image Docker ke repositori. Masuk ke Docker Hub, buka repositori, dan pilih tab Tag. latestTag harus berisi nilai Terakhir Diperbarui yang sangat baru.