In this step we'll unlock the VM that's running your code, and use SSH to peek inside.
SSH into the local devserver
If you've been running the tutorial on the local devserver, you can use this sequence of commands to connect to the virtual machine. You must first connect to the VirtualBox, locate the container running your app, and then connect to the instance:
# SSH into the VirtualBox
$ boot2docker ssh
# List the running containers (note the CONTAINER ID of your instance)
$ docker ps
# Execute a shell inside the container that's running your application
$ docker exec -it <container-id> /bin/bash
# Find the messages file and display its contains
$ ls /tmp
$ more /tmp/messages.txt
# Exit the shell
$ exit
These commands are helpful for debugging in the devserver. Run them from the VirtualBox, not from the container itself:
# shows all processes (running and stopped) along with their exit codes
$ docker ps -a
# display the logs for a container
$ docker logs <container-id>
SSH into a VM
Before you can access a VM in production, you need to unlock your managed VM environment (switch it to user-managed):
- Go to the Developers Console, select your project, and navigate to the instances page.
- From there, select a particular instance
- At the top of the console page that displays your instance details, click on the SSH button. This will unlock the instance and open a terminal window where you are now ssh'd into your machine.
Now that you are in the machine, you need to install the container_exec tool. Enter these commands:
$ sudo -s
$ curl http://storage.googleapis.com/vmruntime-images/container_exec.tar.gz | tar xzv
$ mv nsenter /usr/bin/nsenter
$ mv container_exec.sh /usr/bin/container_exec
First, you must use the ps command to locate the container running your instance:
# List the running containers
$ sudo docker ps
The first two columns of output show each Docker container ID along with its image name. Look for a container whose image includes your project ID. For instance, if your project ID is "vm-demo" you'll see an entry like this (some columns have been removed for clarity):
CONTAINER ID IMAGE ... NAMES
642fd53c2ad1 vm-demo.default.1:latest ... grave_mccarthy
Note the name of the image and use the container_exec command to ssh into the container and run a shell:
# Run a shell in a container
$ container_exec <container-name> /bin/bash
# Find the messages file and display its contains
$ ls /tmp
$ more /tmp/messages.txt
# Exit the shell
$ exit
These commands are helpful for debugging in the devserver. Run them from the VirtualBox, not from the container itself:
# shows all processes (running and stopped) along with their exit codes
$ sudo docker ps -a
# display the logs for a container
$ sudo docker logs <container-name>