To use docker for your project you will need to know few things:
- Pull Docker image: Its an Operating system image placed on Docker repository which you can pull into your machine.
- Create Contianer: Its a process of using the image you have downloaded and making it a runnable virtual machine.
- Run Contianer: To run an instance of the container OS.
- Expose Contianer: It allows you to access running contianer elements like ports/volume/terminal from host machine.
docker pull image_repo_name:tag
You can go here https://hub.docker.com/search/?type=image to grab an image of OS required for your poject.
Lets say I want to run a webserver, in that case I can use apache image as docker pull httpd:latest where httpd is the repo name and latest is the tag or version.
docker --create --name containerName image_repo_name:tag
For example if I like to create a container with apache then docker --create --name mywebserver apache:latest
docker run -it --name containerName
docker run -it --name containerName -p 80:80 -v ./myfolder:/var/www/html
Where p means publish but you can think it as a host vs guest port mapping. Here I am mapping host port 80 wuth guest/container port 80 -v denotes volume and we map host and container volumes.
To start an existing container docker start containerID
To stop an existing container docker stop containerID
To list all running images docker image
To list all running and dormant images: docker image -a
To list all running contianers docker ps
To remove image docker rmi imageID
To remove container docker rm containerID (remember to stop the container before removing it)
To Execute a command or access container terminally docker exec -it contianerID /bin/bash
You can pull image, configure the container and expose ports and volume all from one place using DockerFile.