If you want a reproducible image that you can push to a registry and brag about in your CI logs use a Dockerfile. If you want to start three containers that pretend to be an application for local testing use docker compose. One is a recipe for an image. The other is a party planner for containers.
Dockerfile defines how to build images. It lists base image layers copies configuration and sets the default process. This is the place to pin versions optimize layers and use multi stage builds to keep images tiny. Docker compose uses a yaml file to declare services networks and volumes so multiple containers can start together with one command. Compose handles environment variables port mapping and simple scaling for development or small deployments.
Build an image from a Dockerfile with a simple command
docker build -t myapp .
Start services with docker compose
docker compose up
Minimal docker compose yaml example
version: '3.8'
services:
web:
image: myapp:latest
ports:
- "8080:80"
environment:
- DATABASE_URL=postgres://db:5432/mydb
db:
image: postgres:14
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:
Compose is not a full production orchestrator. If you need advanced scheduling high availability or complex service discovery look at Kubernetes or a managed orchestration service. Also remember that docker compose networks are convenient but different from cloud networking so test in an environment that resembles production.
Use Dockerfile to build and Docker Compose to run. Keep build logic in the Dockerfile and runtime wiring in compose. Treat images as immutable artifacts and use compose for local development stacks and simple deployments. Now go build something and try not to commit a secret to the image like it is still 2015.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.