Docker Certification Training Course : Lecture 2

docker exec -it <running container id> <name of command shell (bash, sh, ksh)> – command used for entering the shell of the running container (for entering an interactive mode) ; to come out of interactive mode without stopping (exiting) a container Ctrl + P + Q command should be used (exit does not fit the requirements since it stops the container)

docker stop <running container id> – command that puts the given container into Exited state

docker start <running container id> – command that starts the given container

docker stop is so called graceful stop of the Docker Container (afeter stop Container status is Exited(0) ) ; there are other (not graceful) ways to stop a container: docker kill <running container id> – command that puts Container into Exited(<non-zero value>) state

docker kill should be used for forceful containers stopping

docker exec <running container id> <command to execute> – command that executes <command to execute> inside the Docker Container without entering container shell

docker logs <container id > – command that shows logs of specific container

docker logs -f <container id> – command that shows continuous logs of  specific container (in real time)

docker container prune – command that will delete all containers which are not in running state

df (abbreviation for disk free) – Unix command that is used to display the amount of available disk space for file systems on which the invoking user has appropriate read access ; df -h displays the data in more easily human readable units, such as KB, MB, GB or TB

docker top <running container id> – command that shows the most heavy (most resource consuming) processes inside the defined container

docker stats – command that shows  cpu and memory usage by containers

docker system (?)

By default any applications inside any Docker Container are not accessible from outside world. To expose particular Container port binding should be used. The port number that is assigned to Docker Container applications for an access from outside world is in the range of 32768-65535.

docker run -d -P (in uppercase) <Docker Image name> – command that assigns outside port number for Docker Container application

curl ifconfig.co – command that displays public ip address of Virtual Machine (used for access to Docker Containers from outside)

<Virtual Machine ip address>:<outside port number> – command to access Docker Container application from outside world

When Docker Container application port is exposed to outside world, the command docker ps output shows 0.0.0.0:<outside port number> in PORTS column. 0.0.0.0 means host Virtual Machine ip address (same as 127.0.0.1)

docker -d -p (in lowercase) <outside port number>:<Docker Container application port number> <Docker Image name> – command that allows user to define outside port number for Docker Container Application manually. Note that in this case outside port number is not confined to the range between 32768-65535

docker port <container id> – command that shows port binding in the defined container (if there are no bindings, the output will be empty) ; docker ps and docker inspect can also be used to find port bindings

docker cp <file name on local host> <running Docker Container id>:<directory inside Docker Container> – command to copy file from local host to Docker Container file system

docker rename <old Docker Container name> <new Docker Container name> – command that changes Docker Container name

docker run -d –name <Docker Container name> <Docker Image name> – command that lets defining Docker Container name manually

By default, Docker Containers will stop if Docker or local host is restarted. This policy can be changed (the policy is applied for every Docker Container separately, it is applied when creating Docker Container, like docker run -d –restart always nginx). There are four modes of restart policy :

  • no (default) : Docker Container is not restarted
  • always : Docker Container will come into Up state irrespective of its previous state
  • unless-stopped : previously running Docker Container will come back into Up state
  • on-failure : Docker will attempt to start container that was Exited not gracefully (with non-zero code)

docker run –memory 500M nginx – example of command that limits Docker Container memory usage to 500M (for cpu it is –cpu=”<cpu value in percantage (like “.5″)>”)

docker rm <container id> – command that removes the given Docker Container. Only previously stopped containers can be removed, or docker rm -f <container id> command should be used

docker stop $(docker ps -a -q) – command that stops all running Docker Containers (output of docker ps -a -q command is a set of container ids and is submitted to docker stop command)

docker rm $(docker ps -a -q) – command that deletes all stopped Docker Containers (or all Docker Containers if followed by -f parameter)

Previous Next

Leave a Reply

Your email address will not be published. Required fields are marked *