Basic Commands
To download/pull the images from the dockerhub(public repo):
docker pull <image-name>
Example:
docker pull ubuntu
docker pull jenkins
To run the docker container from the image:
docker run [options] <image name> <command to execute>
Example1:
Run ubuntu docker image, and execute "ls -l"
sudo docker run ubuntu ls -l
After execution, this container will be in stopped state. It has to be manually cleaned
Example2:
Automatically remove the container when its stopped using "--rm flag"
docker run --rm ubuntu ls -l
Example3:
Running containers as background process (-d)
sudo docker run -d ubuntu
Example4:
Running interactive command in docker (-i interactive, -t emulates text terminal)
docker run --rm -i -t ubuntu bash
Operational Commands:
To see the list of contrainers and status:
docker ps -a
Note: stopped container, running container all will be listed.
To Stop the Running container:
docker kill <id>
docker kill 522d8f21253c
To Remove the docker container:
docker rm <container-id>
docker rm 06711c8bc905
To check the logs of the docker:
docker logs <dockerid>
To attach to the docker:
docker attach <docker id>
To detach from the attached docker:
press CTRL + P + Q
To show the stats of the docker:
docker stats <docker id>
To know the Docker Config details(image,id, ip etc):
docker inspect <docker id>
To enabled the port fowarding
-p <localport:remoteport>
sudo docker run -d -p 80:80 ubuntu
Images:
To list the docker images :
This command lists the image available in your system.
docker images
To remove the docker image:
docker rmi <image id>
docker rmi da5939581ac8
To pull the image from the docker hub:
docker pull <image name>
docker pull ubuntu
To show the history of the images:
docker history <imageid>
Note : history means changes done in the image.
Build the Docker image from Docker file:
First you need to move to the working dir (where you have the relavent files for build the dockerimage)
docker build -t <repo:tag> -f <path to the Docker file> .
cd sms/
sudo docker build -t suresh/sms:v1 -f Dockerfile .
cloud@mkube:~/sms$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
suresh/sms v1 b8493cb930f7 52 seconds ago 357MB