Docker is a container management system that helps easily manage Linux Containers. It lets us create images in virtual environments on our laptop or development environments. The actions that we do on containers and its corresponding behaviour remains same when we run them in production environment.
Docker Commands :
$docker --help : It gives full list of all Docker commands.
$docker <COMMAND> --help : To get additional help pertaining for the given command.
$docker version : gives the information about docker installation.
Search Docker Images :
$docker search <search-term> for e.g docker search nginx
Pulling a Docker Image:
$docker pull tutum/ubuntu
List Docker Images :
$docker images
Remove Docker Image:
$docker rmi ubuntu:trusty
Run a Docker Image:
$docker run -i -t image_name:tag /bin/bash
-i gives an interactive shell
-t will assign a pseudo-tty
Run Docker Image as Daemon
<pre>
$docker run -d image_name:tag for e.g. $docker run -d ubuntu:trusty
</pre>
View the running container/s:
$docker ps
Expose the Docker ports in Daemon mode
$docker run -d -p 8080:80 ubuntu:trusty (port 8080 of container is mapped to port 80 of host)
Check the logs of Docker Container
$docker logs container_id or name
Kill a Docker Container:
$docker kill container_id or name
Stop a Docker Container:
$docker stop container_id or name
Get the stats of Docker Container:
$docker stats container_name
$docker top container_name
Remove the container
$docker rm container_name
BUILDING A DOCKER IMAGE
$docker build --help
$docker build -f path_to_Dockerfile -t REPOSITORY:TAG
REPOSITORY mostly username is used for Docker Hub and <TAG> is the container name.
Building with multiple config files
Create a new directory to hold config files and CD into that directory before executing the build command.
$docker build -t REPOSITORY:TAG
DATA VOLUMES
Mounting a single volume
$docker run -it -v /user/home ubuntu /bin/bash
Mounting multiple volumes
$docker run -it -v /user/home -v /tmp ubuntu /bin/bash
Mounting local directory inside the Docker Container
$docker run -it -v /user/home:/data ubuntu /bin/bash
Mounting in Read Only mode
$docker run -it -v /user/home:/data:ro ubuntu /bin/bash
We can verify the mounts by issuing :
$docker inspect container_id
DATA VOLUMES CONTAINER