- Introduction
- List images, with their names and IDs
- List containers, with their names and IDs
- Connect to the database
- Up, Down, Start and Stop
- Volumes
- Connect into a container
- Make changes and build your own images
- Check container logs to check progress or track down any errors
- Windows 10 environment
- Linux environments
- MacOS environments
Docker is a software environment that provides pre-built machine images and customisation of these images. Its role is to make it easy to package, share and deploy pre-configured images of an operating system plus the necessary software for a specific purpose.
In many ways docker is akin to virtual machines (e.g., VirtualBox and VMWare) but offers a managed, repeatable and scalable way to create and share images that include an operating system plus pre-configured software.
Docker images are publicly shared through Docker Hub. You can use this to search for many kinds of pre-built images to use.
For example, the Open Data Cube partnership (ODC) provides docker images for many of its github repositories. The CSIRO datacube training environment also provides a public docker image.
Dockerfile
and docker-compose.yml
scripts allow us to build-on and adapt an existing docker image.
The CSIRO datacube training environment uses Dockerfile
and docker-compose.yml
scripts adapted from those provided by ODC and create a datacube environment suited to the "power-user" needs of CSIRO science teams.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
csiroeasi/easi-training-pc latest af0f9050058d 3 weeks ago 1.59GB
postgres alpine 9ca7fdaec623 4 weeks ago 70.8MB
Remove or delete and image
$ docker image rm REPOSITORY[:TAG]
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
11c215be8d9b csiroeasi/easi-training-pc:latest "/usr/local/bin/tini…" 10 seconds ago Up 8 seconds 0.0.0.0:5678->5678/tcp, 0.0.0.0:8888->8888/tcp easi-pc-py36_opendatacube_1
993c76da5286 postgres:alpine "docker-entrypoint.s…" 11 seconds ago Up 9 seconds 0.0.0.0:5432->5432/tcp easi-pc-py36_postgres_1
The CSIRO datacube training containers open (map) a set of ports that allow connections into the containers from software outside of the containers:
- 5678 - enable debugging with Visual Studio Code
- 8888 - enable a browser to connect to the notebooks via http://localhost:8888
- 5432 - enable connections to the postgres server and the datacube database
The password is given in docker-compose.yml
$ psql -h localhost -p 5432 -U odc
Password for user odc:
Up and Down are used with docker-compose
to create and remove containers, respectively. The associated images will be created if they do not exist locally already.
Start and Stop are used with docker
to (re)start and pause containers. The container state is retained between start and stop cycles.
The general workflow is:
$ docker-compose up -d # create containers; reads docker-compose.yml
$ docker exec -t -i [NAME] /bin/bash # access a container
$ docker stop [NAME] # pause a container
$ docker start [NAME] # restart a container
$ docker-compose down # remove containers but retain images; reads docker-compose.yml
The datacube database is created in a persistent volume, which is persistent through Up, Down, Start, Stop cycles.
$ docker volume ls # list volumes
DRIVER VOLUME NAME
local easi-training-pc-postgres-data
$ docker volume rm [VOLUME NAME] # remove a volume
$ docker volume prune # remove all orphaned volumes
The CSIRO datacube training containers will connect you in as user "root", which will let you mount network drives and install additional software
$ docker exec -t -i [NAME] /bin/bash
root@[hash]: exit # logout of the container
- Edit
DockerFile
or the associated scripts - Create a new image with
docker build
. You will need to fix any errors - Edit
docker-compose.yml
to use the new image. You will need to fix any errors
$ export DOCKER_BUILDKIT=1 # smarter caching and output, for docker>=18.06
$ docker build -t NAME:TAG . # reads DockerFile; NAME:TAG can be anything you like
# Edit docker-compose.yml to use the NAME:TAG image
$ docker-compose up -d
Often easiest to use in a separate shell with the -f|--follow
option
$ docker logs -f [CONTAINER NAME]
There are a few combinations of software that you can use, depending on your preferences. Full details are not provided here. If you require trouble-shooting help then your first option is the internet as its quite likely someone has already tried what you are trying (much of what we know has been found this way). If you're still stuck then contact us and we will provide what guidance we can.
Create an account and download the software from www.docker.com. For most commands and operations you will need to use one of, for example, PowerShell or Command Prompt, Windows Subsystem for Linux, or Visual Studio Code (includes a shell).
Enable Hyper-V
- Add or remove programs
- Programs and features (right hand side)
- Turn Windows features on or off
- Scroll down to Hyper-V
- Turn everything on
The docker commands above should work as described.
- Get Ubuntu from the Microsoft Store
- Follow https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly to connect to Docker CE for Windows.
- Note that its necessary to make the change such that C: mounts to /c (not the default /mnt/c); otherwise
docker-compose up -d
will fail.
- Note that its necessary to make the change such that C: mounts to /c (not the default /mnt/c); otherwise
- Mount other mapped drives. Mounts other than 'C:' will need to be reset at the start of each session.
- (manual) At command line
sudo mount -t drvfs X: /x
- (automatic) In
/etc/fstab
add a line likeH: /h drvfs defaults 0 0
- (manual) At command line
- Get Python for Windows, from https://www.python.org
- Get the Docker extension
The docker commands above should work as described.
Ubuntu example given here only.
- Follow https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly to connect to docker's apt repository
The docker commands above should work as described.
TBC.