Lesson 2 tells us how to use Docker and run an instance on Google Cloud Platform.
Using Google Compute Engine, we first create a new Linux image and connect to it through SSH, then run Docker containers on top of it.
The main advantage of containers is that you can run several isolated environments on the same operating system. You can pull an image from a repository and manage instances with the docker command line tool much as you would a regular UNIX process.
Docker images can be either downloaded or custom-built using Dockerfiles. The developer’s responsibility here is to deliver the application AND the configuration file for the container.
The images can then be pushed to a public or private registry for reuse. The most notable are Docker Hub, Quay and Google Cloud Registry.
Useful commands
Creating an instance called ubuntu on Compute Engine.
1 | gcloud compute instances create ubuntu --image-project ubuntu-os-cloud --image ubuntu-1604-xenial-v20160420c |
Connecting to it over SSH.
1 | gcloud compute ssh ubuntu |
Running nginx on the remote host.
1 | michel@ubuntu:~$ sudo apt-get install nginx |
Installing docker on the operating system.
1 | sudo apt-get install docker.io |
Listing Docker images and downloading the nginx image.
1 | michel@ubuntu:~$ docker images |
Running an image. The image is pulled automatically if it is not found locally.
1 | michel@ubuntu:~$ docker run -d nginx:1.10.0 |
Checking which instances are running.
1 | michel@ubuntu:~$ docker ps |
Stopping a Docker instance.
1 | # Stopping instance |
Getting the IP address of a Docker instance.
1 | docker inspect [container id] |
A sample Dockerfile defining a base image (Alpine Linux).
1 | FROM alpine:3.1 |
Then build the Docker image and run it as described above.
1 | docker build -t hello:1.0.0 |
Pushing an image to a registry.
1 | docker tag hello:1.0.0 username/hello:1.0.0 |
To check later
- GCP Documentation - gcloud compute instances create
- The list of images available can be obtained with
gcloud compute images list:centos,cos,debian,rhel,suse,suse-sap,ubuntu-os,windows,windows-sql…
- The list of images available can be obtained with
- Docker docs - Deploy a registry server