Docker - Dockerfile - Image - Containers
Topics
● What is Docker File
● How to create Dockerfile
● How to build images from docker file
● Basic Commands
● Build dockerfile, image and container for tomcat server
● FROM → from where the image is created
● RUN → for executing certain commands while building image
● CMD → executes in command line while creating container
Links
https://docs.docker.com/engine/reference/builder/
Building Basic Dockerfile - Image - running Container
#mkdir Dockerfiles
#cd Dockerfiles
#touch Dockerfile
#vim Dockerfile
press i for insert mode
#docker images → to list all images
#docker build <location of dockerfile> → building docker image if you are in diff dir
#docker build . → building docker image if you are in same dir
#docker build -t <image name>:tag . → building docker image with user defined
name
Image name should be always small letters and it needs at least one arg
#docker run <image id>
Tomcat Docker
#docker build -t mytom . → for building image
#docker run -itd -p 8080:8080 mytom → for running container
Docker - Compose
● what / why - Docker Compose
● How to install
● How to create docker compose file
● how to use docker compose file to create services
● basic commands
Links
https://github.com/docker/compose/releases
Docker compose
tool for defining & running multi-container docker applications
use yaml files to configure application service (docker-compose.yml)
can start all services with a single command : docker compose up
can stop all services with a single command : docker compose down
can scale up selected services when required
#docker-compose -v → to check docker compose version
curl -L
https://github.com/docker/compose/releases/download/1.24.0-rc1/docker-compo
se-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
#docker-compose -v
Create docker image and docker-compose file in same location
Docker File
After creating docker image -- write yml file
#docker-compose config → to check compose file written correctly
#docker-compose up -d