Installation Of Docker
To get up and running with docker you need to install docker into your system. Make sure docker is installed and running. Installing Docker is easy just a setup to install download from here.
Once you have it installed open “Terminal” and type “docker”. If you got it right you should have docker data displaying on “Terminal”.
How it is all works
Docker runs around “Docker File”. That we create to create docker images and containers. There is a library of docker images check here.
Now to understand the concept how docker works you should check docker commands and play with them a little.
Docker Commands
Show all docker commands
docker
Check Docker version
docker version
Docker information
Docker info
List of all containers
docker ps or docker container ls
Create and run container in foreground
docker container run -it -p 80:80 imageName //incase we are creating container from nginx image docker container run -it -p 80:80 nginx
Create and run container in background
docker container run -d -p 80:80 imageName //incase we are creating container from nginx image docker container run -d -p 80:80 nginx
Give name to a container
docker container run -d -p 80:80 --name anyNameYouWant nginx //In case setting name equals nginx_local docker container run -d -p 80:80 --name nginx_local nginx
List all containers running + not running
docker container ls -a
Stop a container
docker container stop containerIdHere
Stop all running containers
docker stop $(docker ps -aq)
Remove all containers
docker rm $(docker ps -aq) //remove using force docker rm $(docker ps -aq) -f
Remove container
//remove single container docker container rm ContainerIDHere //remove using force docker container rm ContainerIDHere -f //removing multiple containers docker container rm ContainerIDHere AnotherContainerIDHere AnotherContainerIDHere
Get logs
docker container logs ContainerName
Inspect a container
docker container inspect ContainerName
Getting Into container
docker exec -it ContainerId sh //incase creating a container and bash into it docker container run -it ImageName bash
*********************
Dealing with Images
*********************
List of all images
docker images
Pull Image from docker hub
docker pull imageNameHere //Incase of nginx image docker pull nginx
Remove all images
docker rmi $(docker images -a -q) //using force docker rmi $(docker images -a -q) -f
Remove image
docker image rm ImageIdHere
*********************
Docker Networks
*********************
List all available networks
docker network ls
Inspect a network
docker network inspect networkNameHere
Create network
docker network create networkName
Create container on a network
//incase of image is nginx docker container run -d --network networkNameHere nginx
Connect existing container to network
docker network connect networkNameHere containerNameHere
Disconnect container from network
docker network disconnect networkNameHere containerNameHere
Detach network
docker network disconnect
*********************
Docker File
*********************
Building image from Docker File
docker image build -t customImageName
Running image
docker container run -p 80:80 --rm customImageName
*********************
Bind Mount
*********************
Setting up Bind Mount
docker container run -p 80:80 -v $(pwd):/usr/share/nginx/html nginx
You must log in to post a comment.