QwikLabs & Google Cloud Platform — Accessing from local machine
Tags: docker, tutorial, qwiklabs, gcp
Published: 2019-10-20 09:22:46

---
title: QwikLabs & Google Cloud Platform — Accessing from local machine
published: true
description: 
cover_image: https://miro.medium.com/max/4713/0*x3YVcxrPoTvJ8XBT
tags: docker,tutorial, qwiklabs,gcp
---

I have been using QwikLabs for quite a while for practicing the google cloud courses online. Now the thing with Google Cloud is that it provides everything inside the browser only, even the terminal access, called as console. But I wanted to be able to access the Google Cloud console from my local terminal for the ease of typing and personal habit of comfort in using the terminal.

I wasn’t sure if that was possible, since the Google Cloud console authorizes you for every action, implicitly, without you even realizing. So I googled a bit and found that Google Cloud has a docker image for its SDK, which has all the functionalities built into it, to let you interact with the Google Cloud platform. I decided to give it a try.

So here is what I did from start to end to get access to my Google Cloud platform from my local terminal. First of all, you need to have docker engine installed on your local machine, to be able to use the docker image.

```
vishal@localhost ~> curl https://get.docker.com | sudo bash -
....
....
vishal@localhost ~> sudo usermod -aG docker vishal
vishal@localhost ~> 
```

At this point, you have to logout and login again for the last docker command to take effect. Open the terminal and start typing again.

```
vishal@localhost ~> docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
vishal@localhost ~> docker pull google/cloud-sdk:latest
latest: Pulling from google/cloud-sdk
4a56a430b2ba: Pull complete 
d2bb1ccc2537: Pull complete 
afb7ad8daa33: Pull complete 
Digest: sha256:ddde4e707ef9c6ff3c93d93a9424ddcc7808c8b4aa51e2bb9326b5cf6614f26b
Status: Downloaded newer image for google/cloud-sdk:latest
docker.io/google/cloud-sdk:latest
vishal@localhost ~>
vishal@localhost ~>docker image ls
docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
google/cloud-sdk    latest              c39e653d9cee        3 days ago          1.78GB
vishal@localhost ~>
vishal@localhost ~> docker run --name local-gcloud-access -it google/cloud-sdk:latest bash
root@4993feef1d6d: gcloud auth list
          Credentialed Accounts
ACTIVE  ACCOUNT
*       <some-google-account>
To set the active account, run:
    $ gcloud config set account `ACCOUNT`
root@4993feef1d6d: gcloud config list project
[core]
project = 
Your active configuration is: [default]
root@4993feef1d6d:
```

At this point, we know that since none of project have been selected or currently active, so we need to select the project before we can start interacting with Google Cloud.

```
root@4993feef1d6d: gcloud auth login
```

This would produce a long google url which you have to open in browser and login with proper credentials. Once you are logged in, you will see a long code on the screen which you need to copy and past it the terminal. If the code is correct, your credentials will be activated in the terminal.
But wait, we aren’t done yet. Remember, you need to select project before you begin. So visit — https://console.cloud.google.com/

From the top left, you will a see dropdown, which will show a list of all the project available for you. Copy the name of the project with which you want to work with. Return to the terminal and execute the command

```
root@4993feef1d6d: gcloud config set project <name-of-the-project>
```

And we are all set. Now you can start executing the command from your local terminal.

Last but not the least, as long as you don’t delete the container, your last auth credentails are saved inside it. Which means that when you stop and start the docker container again, you have have the last login credentials still activated. So always be sure to check which account & project is currently active, before you start shooting commands to GCP from your local terminal.

That’s all folks.

Link to my blog - https://vishalraj.blog/qwiklabs-and-google-cloud-access-with-docker/