[GCP] Until you push the local Docker image to the Container Registry
Overview
Work to push the container image developed and built in the local environment from the local to the repository of "Container Registry"
reference
https://cloud.google.com/container-registry/docs/pushing-and-pulling#push_the_tagged_image_to
procedure
1. gcloud settings
- Install the gcloud command in your local environment
- https://cloud.google.com/sdk/docs/quickstart-macos?hl=ja
- Initial setting
2. Create a service account for Push / Pull of the image
When using your own user account, if the projects are linked in various ways, you are afraid of making a mistake in selecting the project ID, so create a dedicated service account.
- Create a service account
--Working on the console
- Authority settings
--The container image of "Container Registry" is managed by Cloud Storage, and the authority is just to grant the "Storage administrator" authority of Cloud Storage.
- https://cloud.google.com/container-registry/docs/access-control#grant
https://cloud.google.com/sdk/docs/authorizing?hl=ja#authorizing_with_a_service_account
- Create a key for the service account and set up authentication locally
gcloud auth activate-service-account
- https://cloud.google.com/sdk/docs/authorizing?hl=ja#authorizing_with_a_service_account
3. Docker authentication settings
Settings for using gcloud as a Docker authentication helper
- Run
gcloud auth configure-docker
locally
4. Push Docker image
- If you have multiple accounts, switch accounts below.
gcloud config set account [ACCOUNT]
- Tag the local image with the registry name
--Naming convention: [HOSTNAME] / [PROJECT-ID] / [IMAGE]
-[HOSTNAME]: Select from the following. This will determine where to save the image.
--gcr.io hosts the image in a data center in the United States, but its location is subject to change in the future.
--us.gcr.io is a storage bucket that hosts the image in a data center in the United States, but is independent of the image hosted by gcr.io.
--eu.gcr.io hosts the image in the European Union.
--asia.gcr.io hosts the image in a data center in Asia.
-[PROJECT-ID]: Project ID of the target Google Cloud project
-[IMAGE]: Name of container image
--Tagging command:
docker tag [local image name or image ID] [registry name]: [tag (latest if not specified)]
- Push
--
docker push [registry name]: [tag (latest if not specified)]
If you push a new one, a repository will be created on the Container Registry.