Docker
Docker containers allow you to define a VM-like environment specified by a series of steps in a Docker configuration file (Dockerfile
), and then run your environment on various host platforms (e.g. Linux, MacOS, Chrome OS). We use Docker containers to run our Development Environment, as well as to run binaries on the Google Cloud platform.
Table of contents
Installation
You can install Docker on Linux or MacOS. On Chrome OS, you can install Linux and then install Docker within the installed Debian Linux. Docker is pre-installed on Cloud Shell.
After installation you can verify Docker works by running the following from the command line / terminal:
$ docker run hello-world
Example Usage
Building
Build the environment specified by docker/Dockerfile
, tagging the result with my_image
, with the current directory as the source:
$ docker build -f docker/Dockerfile -t my_image .
Running
Run the latest variant of my_image
, removing the container after it stops, mapping port 8080 locally to port 8080 in the container, naming the created container my_run
:
$ docker run --rm -p 8080:8080 --name my_run my_image:latest
Stopping a run
Stop the container named my_run
:
$ docker container stop my_run