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
ADDandCOPYof 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? COPYis only to make sure that a file exists to be used “in the build context”, for example, copypackage.jsonbefore executingnpm iinDockerfile
Up and logs:
docker-compose updocker-compose logs --follow service-name
EXEC vs RUN:
EXECreuses existing containersRUNcreates new ones
EXPOSE vs PORTS:
EXPOSEis only accessible within containersPORTScan be accessed on hosts
