2026-01-26 - LDIAMOL_3

| 2 min read

chp 3:

  • registers like docker hub are image servers that hold docker images
  • docker image: kinda like a big zip file with the application and what it needs to run
  • images aren't one file, each image could have multiple layers, each its own file/entity
  • docker container run -d --name web-ping diamol/ch03-web-ping:2e
    • -d => --detach
    • --name => give the running container a friendly name, easier to use than container-id
  • docker containers can be passed env vars
  • docker container run --env TARGET=google.com diamol/ch03-web-ping:2e
    • --env [var]=[value]
  • Dockerfile
    • FROM: image to build on top of
    • ENV: env vars
    • WORKDIR: creates and sets the working dir
    • COPY [source path] [target path]: copy from local to the image
    • CMD: command to run when docker starts a container based on this image
  • Building a docker image
    • Docker engine running
    • you need a Dockerfile
    • 1 js file
    • docker image build --tag [image name] [directory where dockerfile and code is]
      • the directory can just be . for curdir, its the context that docker builds based on
  • the order of the commands in the Dockerfiel matter, you can optimize them so that when building it uses as much of cached layers as possible making builds faster and use up less bandwidth
    • place lines that are likely to change lower in the file
    • the cmd line doesn't have to be in the end but it has be after the from
    • if a line is changed docker doesn't only rebuild it but it rebuilds all layers after it
    • layers are shared across containers and images
    • so keeping your layers sensible and going from lest to most likely to change makes for happier builds

lab: append to a text file on an image and run it

  • how I did it:
    • docker container cp image/file.txt local-file.txt
    • echo monkey >> local-file.txt
    • docker container cp local-file.txt image/file.txt
    • docker container commit container-id
  • the solution
    • run in interactive, update the file directly, commit, and run again with cat filename