

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 Amazon ECR' untuk mendorong ke Docker Hub
<a name="sample-docker-docker-hub"></a>

Untuk mengadaptasi sampel 'Publikasikan gambar Docker ke Amazon ECR' sehingga gambar Docker didorong ke Docker Hub alih-alih Amazon ECR, edit kode sampel. Untuk informasi lebih lanjut tentang sampel, lihat [Contoh 'Publikasikan gambar Docker ke repositori gambar Amazon ECR' untuk CodeBuild](sample-docker.md) dan[Jalankan sampel 'Publikasikan gambar Docker ke Amazon ECR'](sample-docker.md#sample-docker-running).
**catatan**  
Jika Anda menggunakan versi Docker lebih awal dari 17.06, hapus opsi. `--no-include-email`

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

   ```
   ...
     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
   ...
   ```

1. 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 file ZIP yang berisi file, lalu unggah ke bucket input. Jangan tambahkan `(root directory name)` ke file ZIP, hanya file di dalamnya`(root directory name)`.

1. Ganti baris kode ini dari input berformat JSON 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"
         }
       ]
   ...
   ```

1. Buat lingkungan build, jalankan build, dan lihat informasi build terkait.

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