Docker

Docker & Compose 101

Every few weeks where I don’t touch Docker I tend to forget the basics:

Docker:

  • Why use docker: so that with the same instructions (dockerfile), you will always get the same result in any environment.

Container vs Host:

  • Instead of running different processes in OS directly, we run them as “containers” inside docker engine
  • Each container is a service run within docker
  • Host is your own computer’s OS, aka “outside of containers”

Docker compose:

  • A way to define and run multiple containers
  • Can specify dependencies between them

Dockerignore:

  • .dockerignore file only applies to the building of image process, e.g., when doing ADD and COPY of folders
  • To ignore a directory when COPYing, use the syntax **/dir

Why COPY?

  • Why use COPY, when files are going to be synced between host and container anyway?
  • COPY is only to make sure that a file exists to be used “in the build context”, for example, copy package.json before executing npm i in Dockerfile

Up and logs:

  • docker-compose up
  • docker-compose logs --follow service-name

EXEC vs RUN:

  • EXEC reuses existing containers
  • RUN creates new ones

EXPOSE vs PORTS:

  • EXPOSE is only accessible within containers
  • PORTS can be accessed on hosts
Standard

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.