Quickstart for Docker

Artifact Registry provides a single location for managing private packages and Docker container images.

This quickstart shows you how to:

  • Create a Docker repository
  • Set up authentication
  • Push an image to the repository
  • Pull an image from the repository

Before you begin

For commands in this quickstart, use either Cloud Shell or any environment where the Cloud SDK is installed. Cloud Shell includes a recent stable version of Docker.

  1. Faça login na sua conta do Google.

    Se você ainda não tiver uma, inscreva-se.

  2. No Console do Cloud, na página do seletor de projetos, selecione ou crie um projeto do Cloud.

    Acessar a página do seletor de projetos

  3. Verifique se a cobrança está ativada para o seu projeto do Google Cloud. Saiba como confirmar se a cobrança está ativada para o seu projeto.

  4. Ative a API Artifact Registry.

    Ative a API

  5. Instale e inicialize o SDK do Cloud..
  6. Install Docker. If you're using a Linux-based operating system, such as Ubuntu or Debian, add your username to the docker group so that you can run Docker without using sudo:
    sudo usermod -a -G docker ${USER}

    Log out and log back in for group membership changes to take effect. If you are using a virtual machine, you may need to restart the virtual machine for membership changes to take effect.

  7. Open Docker. To ensure that Docker is running, run the following Docker command, which returns the current time and date:
  8. docker run busybox date

Create a Docker repository

To add a repository:

Console

  1. Open the Repositories page in the Cloud Console.

    Open the Repositories page

  2. Click Create Repository.

  3. Specify quickstart-docker-repo as the repository name.

  4. Choose Docker as the format.

  5. Under Location Type, select Region and then choose the location us-central1.

  6. Click Create.

The repository is added to the repository list

gcloud

  1. Run the following command to create a new Docker repository named quickstart-docker-repo in the location us-central1 with the description "docker repository".

    gcloud beta artifacts repositories create quickstart-docker-repo --repository-format=docker \
    --location=us-central1 [--description="Docker repository"]
    
  2. Run the following command to verify that your repository was created.

    gcloud beta artifacts repositories list
    

For more information about Artifact Registry commands, run the command gcloud beta artifacts.

Configure authentication

Before you can push or pull images, you must configure Docker to use the gcloud command-line tool to authenticate requests to Artifact Registry.

To set up authentication to Docker repositories in the region us-central1, run the following command:

gcloud auth configure-docker us-central1-docker.pkg.dev

Obtain an image to push

For this quickstart, you will push the official Docker image of Alpine to a repository. Alpine is a minimal Linux distribution, so the container image is about 5MB.

  1. Change to a directory where you want to save the image
  2. Run the following command to get the official Alpine image from Docker Hub.

    docker pull alpine
    

Add the image to the repository

Before you push the Docker image to Artifact Registry, you must tag it with the repository name.

Tag the image with a registry name

Tagging the Docker image with a repository name configures the docker push command to push the image to a specific location. For this quickstart, the host location is us-central1-docker.pkg.dev.

To tag the Docker image, run the following command:

docker tag alpine us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1

Where

  • PROJECT is your Google Cloud Console project ID. If your project ID contains a colon (:), see Domain-scoped projects.
  • us-central1 is the repository location
  • 'docker.pkg.dev` is the hostname for Docker repositories
  • quickstart-image is the image name you want to use in the repository. The image name can be different than the local image name.
  • tag1 is a tag you're adding to the Docker image. If you didn't specify a tag, Docker will apply the default tag latest.

You are now ready to push the image to the repository you created.

Push the image to Artifact Registry

Once docker has been configured to use gcloud as a credential helper, and the local image is tagged with the registry name, you can push it to a repository.

To push the Docker image, run the following command:

docker push us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1

Where PROJECT is your Google Cloud Console project ID. If your project ID contains a colon (:), see Domain-scoped projects.

Pull the image from Artifact Registry

To pull the image from Artifact Registry onto your local machine, run the following command:

docker pull us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1

Where PROJECT is your Google Cloud Console project ID. If your project ID contains a colon (:), see Domain-scoped projects.

You should see output similar to the following:

latest: Pulling from [PROJECT-ID]/quickstart-image:tag1
Digest: sha256:70c42...
Status: Image is up to date for us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1

Clean up

To avoid incurring charges to your Google Cloud account for the resources used in this quickstart, follow these steps.

Before you remove the repository, ensure that any images you want to keep are available in another location.

To delete the repository:

Console

  1. Open the Repositories page in the Cloud Console.

    Open the Repositories page

  2. In the repository list, select the quickstart-docker-repo repository.

  3. Click Delete.

gcloud

To delete the quickstart-docker-repo repository, run the following command:

gcloud beta artifacts repositories delete quickstart-docker-repo --location=us-central1

What's next