Understanding Docker: A Beginner’s Guide for Geophysics Students
A practical introduction to Docker for geophysics students, including images, containers, volumes, and a simple workflow for reproducible seismic data analysis.
Docker helps you package code, dependencies, and runtime settings into a portable unit called a container. For geophysics students, this is useful when running workflows across laptops, lab machines, and cloud systems without “it works on my machine” issues.
This post introduces the core Docker concepts and shows a practical setup for scientific analysis.
Why Docker Is Useful in Geophysics
Geophysics workflows often depend on many tools and libraries (for example numpy, scipy, matplotlib, obspy, and system packages). Managing these manually across systems can be fragile.
Docker helps by:
- Keeping environments reproducible.
- Making collaboration easier.
- Simplifying deployment on servers or HPC gateways.
- Reducing dependency conflicts.
Core Concepts
Image
A Docker image is a read-only template that contains your application and dependencies.
Container
A container is a running instance of an image.
Dockerfile
A Dockerfile is a text file with instructions to build an image.
Volume
A volume lets containers read/write persistent data outside the container lifecycle.
Registry
A registry (for example Docker Hub) stores and distributes images.
Install Docker
Install Docker Desktop (Windows/macOS) or Docker Engine (Linux), then verify:
docker --version
docker run hello-world
If hello-world runs successfully, your setup is ready.
Basic Commands You Should Know
# Pull an image
docker pull python:3.11-slim
# List local images
docker images
# Run a temporary container
docker run --rm -it python:3.11-slim bash
# List running containers
docker ps
# List all containers
docker ps -a
# Remove a container
docker rm <container_id>
Build Your First Geophysics Image
Create a folder and add this Dockerfile:
FROM python:3.11-slim
WORKDIR /workspace
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir numpy scipy matplotlib obspy pandas
CMD ["python", "--version"]
Build the image:
docker build -t geophysics-lab:1.0 .
Run it interactively:
docker run --rm -it geophysics-lab:1.0 bash
Work with Local Data Using Volumes
Bind your local directory so scripts and data stay on your machine:
docker run --rm -it \
-v "$(pwd)":/workspace \
-w /workspace \
geophysics-lab:1.0 \
python your_script.py
This keeps your workflows reproducible while preserving local files.
Example: Quick Seismic Trace Plot with ObsPy
Create plot_trace.py:
from obspy import read
import matplotlib.pyplot as plt
st = read("example.mseed")
tr = st[0]
plt.figure(figsize=(10, 3))
plt.plot(tr.times(), tr.data, lw=0.9)
plt.xlabel("Time (s)")
plt.ylabel("Amplitude")
plt.title(f"{tr.id} | fs={tr.stats.sampling_rate} Hz")
plt.tight_layout()
plt.savefig("trace_plot.png", dpi=150)
print("Saved: trace_plot.png")
Run:
docker run --rm -it \
-v "$(pwd)":/workspace \
-w /workspace \
geophysics-lab:1.0 \
python plot_trace.py
Best Practices for Students
- Pin versions for critical libraries.
- Keep Dockerfiles small and readable.
- Use
.dockerignoreto avoid copying large unnecessary files. - Mount data as volumes instead of baking raw datasets into images.
- Tag images with meaningful versions (
1.0,1.1,2024-12).
Common Pitfalls
- Permission mismatches between host and container files.
- Large image sizes due to unnecessary packages.
- Forgetting to persist outputs using mounted directories.
- Using
latesttags everywhere, which hurts reproducibility.
Conclusion
Docker is a practical skill for modern geophysics work. Once you containerize your analysis environment, you can run the same workflow consistently on different systems with minimal setup effort.
For students, this is one of the fastest ways to make projects reproducible, shareable, and easier to maintain.
Disclaimer of liability
The information provided by the Earth Inversion is made available for educational purposes only.
Whilst we endeavor to keep the information up-to-date and correct. Earth Inversion makes no representations or warranties of any kind, express or implied about the completeness, accuracy, reliability, suitability or availability with respect to the website or the information, products, services or related graphics content on the website for any purpose.
UNDER NO CIRCUMSTANCE SHALL WE HAVE ANY LIABILITY TO YOU FOR ANY LOSS OR DAMAGE OF ANY KIND INCURRED AS A RESULT OF THE USE OF THE SITE OR RELIANCE ON ANY INFORMATION PROVIDED ON THE SITE. ANY RELIANCE YOU PLACED ON SUCH MATERIAL IS THEREFORE STRICTLY AT YOUR OWN RISK.