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
andCOPY
of folders - To ignore a directory when
COPY
ing, 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, copypackage.json
before executingnpm i
inDockerfile
Up and logs:
docker-compose up
docker-compose logs --follow service-name
EXEC
vs RUN
:
EXEC
reuses existing containersRUN
creates new ones
EXPOSE
vs PORTS
:
EXPOSE
is only accessible within containersPORTS
can be accessed on hosts