tempfs mount volume:
- Data is store in hosts memory
- never store data in hard disk
- store information when running container untill stop
–tmpfs /app/tmp:
Example: httpd server need access file faster
docker run -dit --name apache2 --tmpfs /usr/local/apache2/htdocs/:rw,size=64m httpd:latest
Docker compose
- Docker compose define and run multiple container from a single yaml file
compose.yaml or docker-compose.yaml
Basic structure
services:
web:
image/build:
port:
volume:
network:
frontend:
image/build:
port:
volume:
network:
backend:
image/build:
port:
volume:
network:
volumes: # named volumes
demo:
app:
api:
networks:
host:
- app-net
sample docker compose file
services:
apache2:
image: httpd:latest
container_name: apache2_container
ports:
- "80:80"
volumes:
- ./html:/usr/local/apache2/htdocs/
networks:
- webnet
depends_on: ["mysql"]
mysql:
image: mysql:latest
container_name: mysql
ports:
- "3306:3306"
networks:
webnet:
driver: bridge
volumes:
html:
driver: local
Docker compose comands
- docker compose up -d # run docker services , create network and volume
- docker compose ps # list services runing
- docker compose logs -f apache2
docker compose exec apache2 sh`` or/bin/bash“`- docker compose down
- verbose
-vvvdocker compose down -v - docker compose config # validate or view the final configuration
- -f file path
docker compose up -d -f ./app-compose.yaml
common Service keys
image: prebuild image or existing image (image: http:latest)build: build the image from dockerfile (build: ./Dockerfile)port: Publish Port [host:containerport] (“8080:80”)enviroment: set env varaible ( – KEY=Value)
enviroment:
- name: demo
- app: 1.2
- team: devops
env_file: local env file (env_file: .env)volume: mount volume path to container- ./html:/usr/local/apache2/htdocs/- depends_on: starting order or wait for other service (depends_on: [“web”])
network: Attach network to container
networks:
- webnet
restart: Restart policy automatically start container if any failures ( restart: unless-stopped )command: override default command (command: [“java”, “-jar”, “*.jar”])Health-check: container health test (healthcheck: cmd)
Task:
- try convert nop app and database as docker compose yaml file.
