Skip to content

Latest commit

 

History

History
164 lines (102 loc) · 3.08 KB

setup-docker-gcloud.md

File metadata and controls

164 lines (102 loc) · 3.08 KB

Setup Docker and GCloud to Push Docker Images to Google Cloud Container Registry


1. Install Docker

  • Download and Install Docker:

  • Verify Docker Installation:

    docker --version

Warning

If you run docker with sudo, you also need to auth as root. Or docker won't be able to get your credentials!

2. Run Docker Without sudo

To allow your user to run Docker commands without needing sudo.

a. Create the Docker Group (if it doesn’t exist)

sudo groupadd docker

b. Add Your User to the Docker Group

sudo usermod -aG docker $USER

c. Log Out and Log Back In

Log out of your current session and log back in for the group membership changes to take effect.

d. Verify Docker Can Run Without sudo

docker run hello-world

If successful, Docker is configured to run without sudo.


3. Install Google Cloud SDK

  • Download and Install Google Cloud SDK:

  • Verify the SDK Installation:

    gcloud --version

4. Initialize Google Cloud SDK

  • Initialize the SDK:

    gcloud init
  • Follow the Prompts to:

    • Log in to your Google account.
    • Select your Google Cloud project.
    • Set the default region and zone.

5. Enable the Container Registry API

  • Enable the API for Your Project:

    gcloud services enable containerregistry.googleapis.com

6. Authenticate Docker to Google Cloud

  • Configure Docker to Use gcloud as a Credential Helper:

    gcloud auth configure-docker

7. Build Your Docker Image

  • Build Your Docker Image as Usual:

    docker build -t my-image .

8. Tag Your Docker Image for GCR

  • Tag the Image with a GCR Registry Name:

    docker tag my-image gcr.io/your-project-id/my-image:latest

    Replace your-project-id with your actual Google Cloud project ID, and my-image:latest with your image name and desired tag.


9. Push the Docker Image to GCR

  • Push the Tagged Image to GCR:

    docker push gcr.io/your-project-id/my-image:latest

10. Verify the Image in GCR

  • List Images in Your Project’s GCR:

    gcloud container images list
  • View Image Details:

    gcloud container images list-tags gcr.io/your-project-id/my-image

Troubleshooting

If You Encounter Permission Issues Running Docker Without sudo:

  1. Ensure Your User Is in the Docker Group:

    groups $USER

    You should see docker listed among the groups.

  2. Restart the Docker Service:

    sudo systemctl restart docker
  3. Reboot Your System (if necessary):

    • Sometimes a full system reboot is required for the changes to take effect.