Repo to document all experiments with Docker
-
Create mysql container without any volume, create db, stop container data check data
docker run --platform linux/x86_64 -e MYSQL_ALLOW_EMPTY_PASSWORD=true -d mysql
docker exec -it 1d728 mysql
docekr ps
docker stop a5ff6e5baa98
-
Create mysql cotainer with bind mount, create db, stop container and check data
docker run --platform linux/x86_64 -e MYSQL_ALLOW_EMPTY_PASSWORD=true -v $(pwd)/mysql-data:/var/lib/mysql -d mysql
docker ps
docker exec -it 81aa mysql
-
Create mysql container with volume, create db, stop container and check data
docker run --platform linux/x86_64 -e MYSQL_ALLOW_EMPTY_PASSWORD=true -v mysql-data:/var/lib/mysql -d mysql
docker ps
docker exec -it 31 mysql
- Using monorepo vs polyrepo
- Using env specific files to store environmental variables - ./dev.env, test.env
- Accessing env variables using os.getenv in app
- Debugging
- CI: build, run, test, push docker images to docker hub/docker registry
- Smoke test using application port checks
- Use light images - base > slim > alpine
- Copy only required files to image
- Add .dockerignore
- Use exact versions of packages when installing packages using apt
- Use COPY statements as late as possible in dockerfile - allows caching
- Add less changing statements earlier of dockerfile - allows caching
- Every RUN, COPY & ADD adds new layer. Add multiple RUN commands together
- Multistage build
- Add labels - git repo, maintainer build date, build #, git commit hash
- Add --init to add avoid pid 1 problem
- Use tagged images vs latest as latest may change
- Run with non-root. Use USER directive in dockerfile
- Use HEALTHCHECK directive within dockerfile for healthcheck
- Use Linter