If you want to go from zero to container in a few commands and a little smug satisfaction this tiny Docker tutorial will hold your hand and then push you out the door. We build a minimal image for a microscopic app run it in a container and then clean up the mess like a responsible adult.
Your Dockerfile is the recipe book for your image. Keep it small and cache friendly so builds are fast and predictable. Here is a minimal example that uses a slim Python base to run a tiny HTTP server.
FROM python:3.11-slim
WORKDIR /app
COPY app.py .
CMD ["python", "app.py"]
And a two minute app so you actually have something to run. Save this as app.py in the same folder.
from http.server import SimpleHTTPRequestHandler, HTTPServer
PORT = 8000
class Handler(SimpleHTTPRequestHandler):
pass
httpd = HTTPServer(('0.0.0.0', PORT), Handler)
print('Serving on', PORT)
httpd.serve_forever()
Run the builder to produce a tagged image you can run locally. Tagging helps later when you inevitably have multiple versions and a questionable memory.
docker build -t myapp:1.0 .
Notes for the careful and the lazy. Use a small base image like alpine or python slim. Order COPY and dependency steps to make the cache work for you instead of against you. Add a .dockerignore so your build context does not include five years of logs.
Start the container detached and map a port so your browser can confirm it exists. Give it a name so removing it later is not a scavenger hunt.
docker run -d --name myapp -p 8000:8000 myapp:1.0
If you prefer drama over convenience you can skip detached mode and stare at logs until you feel something.
Make sure your container is alive and serving. Then stop it and remove both container and image when you are done. This keeps your disk from becoming a hoarder.
docker ps
# check that myapp is running
curl http://localhost:8000
# or open http://localhost:8000 in a browser
docker stop myapp
docker rm myapp
docker rmi myapp:1.0
There you go. You wrote a Dockerfile built an image ran a container and cleaned up. This sequence explains how the Dockerfile image and container relate and gives a practical starting point for containerization and devops experiments. Now go forth and containerize, but maybe not the cat.
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.