おれさまラボ

実際に手を動かして理解を深めるブログ。

Google Cloud Shell を使ってみる

Google Cloud Shell は Google Cloud Platform に登録すると使える Linux 環境です。Webブラウザ経由でのアクセスなので便利そうです。

Google Cloud Platform(GCP) への登録

登録には住所やクレジットカード番号が必要です。現在12ヶ月間(300ドル)の無料トライアル期間をやっているので、そちらを利用します。

触ってみる

ログインすると help を入力するといいよ、と言われたのでとりあえず打ってみます。

Welcome to Cloud Shell! Type "help" to get started.
user@machine-id:~$ help

Welcome to Google Cloud Shell, a tool for managing resources hosted on Google Cloud Platform!
The machine comes pre-installed with the Google Cloud SDK and other popular developer tools.

Your 5GB home directory will persist across sessions, but the VM is ephemeral and will be reset
approximately 20 minutes after your session ends. No system-wide change will persist beyond that.

Type "gcloud help" to get help on using Cloud SDK. For more examples, visit
https://cloud.google.com/shell/docs/quickstart and https://cloud.google.com/shell/docs/examples

Type "cloudshell help" to get help on using the "cloudshell" utility.  Common functionality is
aliased to short commands in your shell, for example, you can type "dl <filename>" at Bash prompt to
download a file. Type "cloudshell aliases" to see these commands.

Type "help" to see this message any time. Type "builtin help" to see Bash interpreter help.

5GB の保存領域が使えるようです。また、セッション断から20分経過すると環境がリセットされるそうです。ある意味検証環境には最適ですね。
GCP用のSDKもここから使えるようです。

PATH通ってるところを覗いて、何のコマンドが使えるのか確かめてみます。

user@machine-id:~$ echo $PATH | sed -e "s/:/\n/g" | xargs ls
ls: cannot access '/home/nygmadm/gopath/bin': No such file or directory
ls: cannot access '/google/google_appengine': No such file or directory
/apache-maven-3.3.9/bin:
m2.conf  mvn  mvn.cmd  mvnDebug  mvnDebug.cmd  mvnyjp

/bin:
bash     bzexe         bzmore  cpio  dmesg          fgrep    gzip      lessecho  ls      more        nano           ps        rnano       ss            tar       uname         zcat    zgrep
bunzip2  bzfgrep       cat     dash  dnsdomainname  findmnt  hostname  lessfile  lsblk   mount       netstat        pwd       run-parts   stty          tempfile  uncompress    zcmp    zless
bzcat    bzgrep        chgrp   date  domainname     fuser    ip        lesskey   lsmod   mountpoint  nisdomainname  rbash     sed         su            touch     vdir          zdiff   zmore
bzcmp    bzip2         chmod   dd    echo           grep     kill      lesspipe  mkdir   mt          pidof          readlink  sh          sync          true      wdctl         zegrep  znew
bzdiff   bzip2recover  chown   df    egrep          gunzip   kmod      ln        mknod   mt-gnu      ping           rm        sh.distrib  systemd-hwdb  udevadm   which         zfgrep
bzegrep  bzless        cp      dir   false          gzexe    less      login     mktemp  mv          ping6          rmdir     sleep       tailf         umount    ypdomainname  zforce

/google/go_appengine:
appcfg.py               bulkload_client.py  dev_appserver.py      goapp  google  lib         _python_runtime.py    run_tests.py  wrapper_util.py
backends_conversion.py  bulkloader.py       download_appstats.py  godoc  gopath  LICENSE     RELEASE_NOTES         tools
BUGS                    demos               endpointscfg.py       gofmt  goroot  php_cli.py  RELEASE_NOTES.python  VERSION

/google/google-cloud-sdk/bin:
bootstrapping  bq  cbt  datalab  dev_appserver.py  docker-credential-gcloud  docker-credential-gcr  endpointscfg.py  gcloud  git-credential-gcloud.sh  gsutil  java_dev_appserver.sh  kubectl

/google/gopath/bin:
aebundler  aedeploy  aefix  guestbook  helloworld

/gradle-2.12/bin:
gradle  gradle.bat

/sbin:
agetty           cfdisk      dumpe2fs  fsck.cramfs   getty          ip6tables-restore  killall5  mkfs.bfs          modinfo     raw        shadowconfig       sysctl       xtables-multi
apparmor_parser  chcpu       e2fsck    fsck.ext2     hwclock        ip6tables-save     ldconfig  mkfs.cramfs       modprobe    resize2fs  slattach           tc           zramctl
badblocks        ctrlaltdel  e2image   fsck.ext3     ifconfig       ipmaddr            logsave   mkfs.ext2         nameif      rmmod      start-stop-daemon  tipc
blkdeactivate    debugfs     e2label   fsck.ext4     initctl        iptables           losetup   mkfs.ext3         pam_tally   route      sulogin            tune2fs
blkdiscard       depmod      e2undo    fsck.minix    insmod         iptables-restore   lsmod     mkfs.ext4         pam_tally2  rtacct     swaplabel          udevadm
blkid            devlink     fdisk     fsfreeze      installkernel  iptables-save      mii-tool  mkfs.minix        pivot_root  rtmon      swapoff            unix_chkpwd
blockdev         dmsetup     findfs    fstab-decode  ip             iptunnel           mke2fs    mkhomedir_helper  plipconfig  runuser    swapon             unix_update
bridge           dmstats     fsck      fstrim        ip6tables      isosize            mkfs      mkswap            rarp        sfdisk     switch_root        wipefs

/usr/bin:
[                               docker-runc              gobject-query           lslocks                           pager                      realpath          update-alternatives
2to3                            dotlockfile              gold                    lslogins                          parallel                   recode-sr-latin   update-mime-database
2to3-2.7                        dotnet                   gpasswd                 lsns                              partx                      reindexdb         update-mime-database.real
2to3-3.5                        dpkg                     gpg                     lsof                              passwd                     rename            uptime
aa-enabled                      dpkg-architecture        gpg2                    lspgpot                           paste                      rename.ul         users
aa-exec                         dpkg-buildflags          gpg-agent               luit                              patch                      renice            utmpdump
aclocal                         dpkg-buildpackage        gpgconf                 lxc-attach                        pathchk                    reset             vacuumdb
aclocal-1.15                    dpkg-checkbuilddeps      gpg-connect-agent       lxc-autostart                     pcre-config                resizepart        vacuumlo
addpart                         dpkg-deb                 gpgparsemail            lxc-cgroup                        pdb                        rev               vi
addr2line                       dpkg-distaddfile         gpgsplit                lxc-checkconfig                   pdb2.7                     rgrep             vidir
appletviewer                    dpkg-divert              gpgv                    lxc-checkpoint                    pdb3                       ri                view
appres                          dpkg-genbuildinfo        gpg-zip                 lxc-config                        pdb3.5                     ri2.3             viewres
apropos                         dpkg-genchanges          gpic                    lxc-console                       pee                        rlogin            vim
apt                             dpkg-gencontrol          gprof                   lxc-copy                          peekfd                     rmic              vim.basic
apt-cache                       dpkg-gensymbols          grep-changelog          lxc-create                        perf                       rmid              vimdiff
apt-cdrom                       dpkg-maintscript-helper  grep-changelog.emacs24  lxc-destroy                       perl                       rmiregistry       vim.nox
apt-config                      dpkg-mergechangelogs     gresource               lxc-device                        perl5.24.1                 routef            vimtutor
apt-get                         dpkg-name                groff                   lxc-execute                       perl5.24-x86_64-linux-gnu  routel            vipe
apt-key                         dpkg-parsechangelog      grog                    lxc-freeze                        perlbug                    rpcgen            vmstat
apt-mark                        dpkg-query               grops                   lxc-info                          perldoc                    rsh               vows
ar                              dpkg-scanpackages        grotty                  lxc-ls                            perlivp                    rtstat            w
arch                            dpkg-scansources         groups                  lxc-monitor                       perlthanks                 ruby              wall
as                              dpkg-shlibdeps           grunt                   lxc-snapshot                      pg                         ruby2.3           watch
autoconf                        dpkg-source              gsettings               lxc-start                         pg_archivecleanup          runcon            watchgnupg
autoheader                      dpkg-split               gtbl                    lxc-stop                          pg_basebackup              run-mailcap       wc
autom4te                        dpkg-statoverride        gtester                 lxc-unfreeze                      pgbench                    rview             wget
automake                        dpkg-trigger             gtester-report          lxc-unshare                       pg_config                  rvim              whatis
automake-1.15                   dpkg-vendor              gtk-update-icon-cache   lxc-usernsexec                    pg_config.libpq-dev        savelog           whereis
autoreconf                      dropdb                   gulp                    lxc-wait                          pg_conftool                schemagen         which
autoscan                        droplang                 h2ph                    lynx                              pg_createcluster           scp               who
autoupdate                      dropuser                 h2xs                    lzcat                             pg_ctlcluster              script            whoami
awk                             du                       hd                      lzcmp                             pg_dropcluster             scriptreplay      whois
b2sum                           dwp                      head                    lzdiff                            pg_dump                    sdiff             w.procps
base32                          ebrowse                  helpztags               lzegrep                           pg_dumpall                 see               write
base64                          ebrowse.emacs24          hexdump                 lzfgrep                           pg_isready                 select-editor     wsgen
basename                        echo_supervisord_conf    hg                      lzgrep                            pg_lsclusters              sensible-browser  wsimport
bashbug                         edit                     hg-ssh                  lzless                            pg_receivexlog             sensible-editor   www-browser
bazel                           editor                   host                    lzma                              pg_recvlogical             sensible-pager    X11
bazel-real                      editres                  hostid                  lzmainfo                          pg_renamecluster           seq               x86_64
bison                           elfedit                  htop                    lzmore                            pgrep                      serialver         x86_64-linux-gnu-addr2line
bison.yacc                      emacs                    i386                    m4                                pg_restore                 servertool        x86_64-linux-gnu-ar
bower                           emacs24                  iconv                   make                              pg_upgradecluster          setarch           x86_64-linux-gnu-as
bsd-from                        emacs24-nox              id                      make-first-existing-target        pg_virtualenv              setsid            x86_64-linux-gnu-c++filt
bsd-write                       emacsclient              idlj                    man                               phar                       setterm           x86_64-linux-gnu-cpp
c++                             emacsclient.emacs24      ifdata                  mandb                             phar5                      sftp              x86_64-linux-gnu-cpp-6
c2ph                            enc2xs                   ifnames                 manpath                           php                        sg                x86_64-linux-gnu-dwp
c89                             encguess                 ifne                    mariabackup                       php5                       sha1sum           x86_64-linux-gnu-elfedit
c89-gcc                         env                      infocmp                 mariadb                           php5-cgi                   sha224sum         x86_64-linux-gnu-g++
c99                             envsubst                 infotocap               mariadbcheck                      php-cgi                    sha256sum         x86_64-linux-gnu-g++-6
c99-gcc                         eqn                      innotop                 mawk                              pic                        sha384sum         x86_64-linux-gnu-gcc
cal                             erb                      install                 mbstream                          pico                       sha512sum         x86_64-linux-gnu-gcc-6
calendar                        erb2.3                   instmodsh               mc                                piconv                     shasum            x86_64-linux-gnu-gcc-ar
captoinfo                       errno                    ionice                  mcdiff                            pidproxy                   shred             x86_64-linux-gnu-gcc-ar-6
catchsegv                       etags                    ipcmk                   mcedit                            pinentry                   shuf              x86_64-linux-gnu-gcc-nm
catman                          etags.emacs24            ipcrm                   mcookie                           pinentry-curses            size              x86_64-linux-gnu-gcc-nm-6
cc                              ex                       ipcs                    mcview                            pinky                      skill             x86_64-linux-gnu-gcc-ranlib
certtool                        expand                   iptables-xml            md5sum                            pip                        slabtop           x86_64-linux-gnu-gcc-ranlib-6
c++filt                         expiry                   irb                     md5sum.textutils                  pip2                       slogin            x86_64-linux-gnu-gcov
cgroupfs-mount                  expr                     irb2.3                  mesg                              pkg-config                 snice             x86_64-linux-gnu-gcov-6
cgroupfs-umount                 extcheck                 ischroot                migrate-pubring-from-classic-gpg  pkill                      soelim            x86_64-linux-gnu-gcov-dump
chage                           factor                   isutf8                  mispipe                           pl2pm                      sort              x86_64-linux-gnu-gcov-dump-6
chattr                          faillog                  itweb-settings          mkfifo                            pldd                       sotruss           x86_64-linux-gnu-gcov-tool
chcon                           fallocate                jar                     mkpasswd                          pmap                       splain            x86_64-linux-gnu-gcov-tool-6
chfn                            fc-cache                 jarsigner               msgattrib                         pod2html                   split             x86_64-linux-gnu-gprof
chronic                         fc-cat                   java                    msgcat                            pod2man                    sponge            x86_64-linux-gnu-ld
chrt                            fc-list                  javac                   msgcmp                            pod2text                   sprof             x86_64-linux-gnu-ld.bfd
chsh                            fc-match                 javadoc                 msgcomm                           pod2usage                  sqldiff           x86_64-linux-gnu-ld.gold
cksum                           fc-pattern               javah                   msgconv                           podchecker                 sqlite3           x86_64-linux-gnu-nm
clear                           fc-query                 javap                   msgen                             podselect                  srptool           x86_64-linux-gnu-objcopy
clear_console                   fc-scan                  javaws                  msgexec                           policyeditor               ssh               x86_64-linux-gnu-objdump
cloud_sql_proxy                 fc-validate              jcmd                    msgfilter                         policytool                 ssh-add           x86_64-linux-gnu-pkg-config
clusterdb                       file                     jconsole                msgfmt                            pr                         ssh-agent         x86_64-linux-gnu-python2.7-config
cmp                             find                     jdb                     msggrep                           preconv                    ssh-argv0         x86_64-linux-gnu-python3.5-config
col                             firebase                 jdeps                   msginit                           prename                    ssh-copy-id       x86_64-linux-gnu-python3.5m-config
colcrt                          flock                    jexec                   msgmerge                          print                      ssh-keygen        x86_64-linux-gnu-python3-config
colrm                           fmt                      jhat                    msgunfmt                          printenv                   ssh-keyscan       x86_64-linux-gnu-python3m-config
column                          fold                     jinfo                   msguniq                           printerbanner              stat              x86_64-linux-gnu-python-config
combine                         free                     jjs                     mtrace                            printf                     stdbuf            x86_64-linux-gnu-ranlib
comm                            from                     jmap                    mysql                             prlimit                    strings           x86_64-linux-gnu-readelf
compose                         functions                join                    mysqlaccess                       protoc                     strip             x86_64-linux-gnu-size
corelist                        functions-emulator       jps                     mysqladmin                        prove                      sudo              x86_64-linux-gnu-strings
cpan                            funzip                   jq                      mysqlanalyze                      prtstat                    sudoedit          x86_64-linux-gnu-strip
cpan5.24-x86_64-linux-gnu       g++                      jrunscript              mysqlcheck                        psktool                    sudoreplay        x86_64-pc-linux-gnu-pkg-config
cpp                             g++-6                    jsadebugd               mysqldump                         psql                       sum               xargs
cpp-6                           gapplication             json_pp                 mysqldumpslow                     pstree                     supervisorctl     xdpyinfo
createdb                        gcc                      jstack                  mysql_embedded                    pstree.x11                 supervisord       xdriinfo
createlang                      gcc-6                    jstat                   mysql_find_rows                   pstruct                    symcryptrun       xev
createuser                      gcc-ar                   jstatd                  mysql_fix_extensions              ptar                       tabs              xfd
c_rehash                        gcc-ar-6                 kbxutil                 mysqlimport                       ptardiff                   tac               xfontsel
crontab                         gcc-nm                   keytool                 mysqloptimize                     ptargrep                   tail              xgettext
csplit                          gcc-nm-6                 killall                 mysqlrepair                       ptx                        taskset           xjc
ctags                           gcc-ranlib               last                    mysqlreport                       pwdx                       tbl               xkill
ctags.emacs24                   gcc-ranlib-6             lastb                   mysqlshow                         py3clean                   tee               xlsatoms
ctstat                          gcloud                   lastlog                 mysqlslap                         py3compile                 telnet            xlsclients
curl                            gcov                     lcf                     mysql_waitpid                     py3versions                telnet.netkit     xlsfonts
cut                             gcov-6                   lckdo                   mytop                             pybuild                    test              xmessage
danetool                        gcov-dump                ld                      namei                             pyclean                    tic               xprop
debconf                         gcov-dump-6              ld.bfd                  native2ascii                      pycompile                  timeout           xsubpp
debconf-apt-progress            gcov-tool                ldd                     nawk                              pydoc                      tload             xvinfo
debconf-communicate             gcov-tool-6              ld.gold                 ncal                              pydoc2.7                   tmux              xwininfo
debconf-copydb                  gdbus                    less                    ncurses5-config                   pydoc3                     tnameserv         xxd
debconf-escape                  gdbus-codegen            lessecho                neqn                              pydoc3.5                   toe               xz
debconf-set-selections          gem                      lessfile                newgrp                            pygettext                  top               xzcat
debconf-show                    gem2.3                   lesskey                 ngettext                          pygettext2.7               touch             xzcmp
deb-systemd-helper              gencat                   lesspipe                nice                              pygettext3                 tput              xzdiff
deb-systemd-invoke              geqn                     lexgrog                 nl                                pygettext3.5               tr                xzegrep
delpart                         getconf                  libnetcfg               nm                                python                     troff             xzfgrep
dh_autotools-dev_restoreconfig  getent                   libtoolize              node                              python2                    truncate          xzgrep
dh_autotools-dev_updateconfig   getopt                   line                    nodemon                           python2.7                  ts                xzless
dh_bash-completion              gettext                  link                    nohup                             python2.7-config           tset              xzmore
dh_pypy                         gettextize               linux32                 npm                               python2-config             tsort             yacc
dh_python2                      gettext.sh               linux64                 nproc                             python3                    tty               yes
dh_python3                      gio                      linux-check-removal     npx                               python3.5                  tzselect          zdump
diff                            gio-querymodules         linux-update-symlinks   nroff                             python3.5-config           ucf               zip
diff3                           git                      linux-version           nsenter                           python3.5m                 ucfq              zipcloak
dig                             git-receive-pack         listres                 nslookup                          python3.5m-config          ucfr              zipdetails
dircolors                       git-shell                lnstat                  nstat                             python3-config             ul                zipgrep
dirmngr                         git-upload-archive       locale                  nsupdate                          python3m                   unexpand          zipinfo
dirmngr-client                  git-upload-pack          localedef               numfmt                            python3m-config            uniq              zipnote
dirname                         glib-compile-resources   logger                  objcopy                           python-config              unlink            zipsplit
docker                          glib-compile-schemas     logname                 objdump                           pyversions                 unlzma            zrun
docker-containerd               glib-genmarshal          look                    ocsptool                          rake                       unmkinitramfs
docker-containerd-ctr           glib-gettextize          lorder                  od                                ranlib                     unpack200
docker-containerd-shim          glib-mkenums             lsattr                  openssl                           rcp                        unshare
dockerd                         gnutls-cli               lscpu                   orbd                              rdoc                       unxz
docker-init                     gnutls-cli-debug         lsinitramfs             p11tool                           rdoc2.3                    unzip
docker-proxy                    gnutls-serv              lsipc                   pack200                           readelf                    unzipsfx

/usr/local/bin:
apt-get     console           easy_install-2.7  gem              ipython2     nvm         pip2.7                 pyrsa-encrypt-bigfile  rackup  ruby             toco
bundle      dill_unpickle.py  erb               get_objgraph.py  irb          pasteurize  pygmentize             pyrsa-keygen           rails   saved_model_cli  toco_from_protos
bundler     docker-compose    f2py              iptest           markdown_py  pbr         pyrsa-decrypt          pyrsa-priv2pub         rake    sprockets        virtualenv
chardetect  docker-machine    freeze_graph      iptest2          minikube     pip         pyrsa-decrypt-bigfile  pyrsa-sign             rdoc    tensorboard      wheel
cloudshell  easy_install      futurize          ipython          nokogiri     pip2        pyrsa-encrypt          pyrsa-verify           ri      thor

/usr/local/go/bin:
go  godoc  gofmt

/usr/local/nvm/versions/node/v8.5.0/bin:
bower  firebase  functions  functions-emulator  grunt  gulp  node  nodemon  npm  npx  vows

/usr/local/sbin:

/usr/sbin:
aa-remove-unknown  applygnupgdefaults  cron               fdformat   grpconv          ldattach       pam-auth-update      pwck          rtcwake                 update-initramfs          usermod
aa-status          arp                 delgroup           filefrag   grpunconv        locale-gen     pam_getenv           pwconv        service                 update-java-alternatives  validlocale
accessdb           arpd                deluser            genl       iconvconfig      make-ssl-cert  pam_timestamp_check  pwunconv      sshd                    update-locale             vigr
addgnupghome       chgpasswd           dpkg-preconfigure  groupadd   init.lxc         mkinitramfs    pg_updatedicts       readprofile   tarcat                  update-mime               vipw
addgroup           chpasswd            dpkg-reconfigure   groupdel   init.lxc.static  mklost+found   php5dismod           remove-shell  tunelp                  update-passwd             visudo
add-shell          chroot              e2freefrag         groupmems  invoke-rc.d      newusers       php5enmod            rmt           tzconfig                update-rc.d               zic
adduser            cpgr                e4crypt            groupmod   ip6tables-apply  nfnl_osf       php5query            rmt-tar       update-ca-certificates  useradd
apparmor_status    cppw                e4defrag           grpck      iptables-apply   nologin        policy-rc.d          rsyslogd      update-icon-caches      userdel
user@machine-id:~$

dockerも使えるようなので、個人的には嬉しい。

user@machine-id:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

user@machine-id:~$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
user@machine-id:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES

他にもインストールとか普通にできるので、結構楽しめそうなおもちゃが出来上がりました。