basic knowledge about the docker flow
docker info | grep more #to check which store drive is docker using
docker images #to list downloaded docker images
docker run -ti <image_id> bash #to enter into the container like a
terminal emulator
exit #to exit from the container
docker ps #to check running images (it will not show
stopped containers)
docker ps -a #to show all container
docker ps -l #to show the last container I exited
docker ps -la #to see all stopped and running containers
create an image from a container
docker commit <container_id> #to create an image from a running
container
docker tag <copy the output of the previous command> <image_name_I_choose>
docker images #to check there is the new image I created
or
docker commit <container_name> <new_image_name_i_choose> #to create
an image from a container
docker run --rm -ti <container_id> <command> #to run a command inside the
container without enter in it
docker exec -ti <container_id> bash #to start a shell of that container
create a container running an image (syntax sample)
sudo docker run –name squid -p 3128:3128 b4tman/squid
docker run = docker will pull the image and later start the container
–name = name of the docker container I choose
-p3128:3128 = exposed port 3128 : internal port 3128
b4tman/squid = the image of docker with squid preinstalled
logs
docker logs <container_name> #to check container logs
stop and remove container
docker kill <container_name> #to stop a container
docker rm <container_name> #to remove a container
resource constraints
docker run -- memory maximum-allowed-memory <image_name> <command>
networking
expose = open a port from the container to the external
docker tun --rm -ti -p 8080:8080 -p 8081:8081 --name <container_name_i_choose>
ubuntu:14.04 bash
#open internal port 8080 and connect to external port 8080
#open internal port 8081 and connect to external port 8081
nc -lp 8080 | nc -lp 8081 #to send data with netcat from
port 8080 to 8081
expose udp ports
docker run -p <outside_port_number>:<inside_port_number>/<tcp>or<udp>
#sample
docker run -p 1234:1234/udp
docker network ls
#bridge = network used by the container
#host = when you want the container not have any isolation at all
#none
docker network create <networn_name_i_chose> #to create a new
network for docker containers
docker run --rm -ti --net <networn_name_i_choose> --name
<container_name_chose> .... #to add a container to that network
images
docker images #to list downloaded images
docker ps -l #to list recently stopped container
docker commit <container_id> <image_name_i_chose> #to create an image from
a running container
docker rmi <image_name>
volumes - share data to and from pc and container
virtual discs to store and share data
can be
persistent
ephemeral
share data with the host
mkdir /pc_path/example #to create a folder inside my pc
docker rub -ti -v /pc_path/example:/path_inside_container/ <image_id> bash
#run an image and share a folder
ls /path_inside_container/ #once I am inside the container to see the
shared folder
start - stop - check status of docker service
sudo systemctl is-active docker #to check docker service
status