0% found this document useful (0 votes)
10 views5 pages

Docker

The document provides a comprehensive guide on various Docker commands for managing containers, images, and networks, including how to view logs, monitor resource usage, and manipulate container states. It also discusses methods for handling persistent data, transferring data between containers, and the lifecycle of Docker containers. Additionally, it outlines Docker networking types and the structure of Docker's filesystem.

Uploaded by

swagstarstyle
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Docker

The document provides a comprehensive guide on various Docker commands for managing containers, images, and networks, including how to view logs, monitor resource usage, and manipulate container states. It also discusses methods for handling persistent data, transferring data between containers, and the lifecycle of Docker containers. Additionally, it outlines Docker networking types and the structure of Docker's filesystem.

Uploaded by

swagstarstyle
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

=============================DOCKER======================================

Show container logs: docker logs containerName

Show only new logs: docker logs -f containerName

Show CPU and memory usage: docker stats

Show CPU and memory usage for specific containers: docker stats containerName1 containerName2

Show running processes in a container: docker top containerName

Show Docker events: docker events

Show storage usage: docker system df

show the last N lines of logs docker logs <container_id> --tail N

Follow the Docker container logs docker logs <container_id> --follow

See specific logs docker logs <container_id> | grep pattern

Only show errors docker logs <container_id> | grep -i error

logs from all services in the application docker-compose logs

What are the commands that will create layers? RUN, FROM, COPY,

IP address and gateway details of the container docker Inspect

Command to list all the ports used by a container? docker container port

List all running Containers docker container ls or docker ps

List all containers docker container ls –a or docker ps -a

List containers that are using redis image docker container ls -f "ancestor=redis"

List all running, stopped, paused container and images docker info

List containers that have ports 80 and 443 published docker container ls --filter "publish=80" --filter "publish=443"

List numeric Id’s of 5 last created containers docker container ls — last 5 — quiet
List latest created container docker ps — latest

Remove unused images docker image prune –a

Remove one or more images docker image rm

Remove all unused networks docker network prune

Remove - all stopped containers docker system prune (Remove unused data)

- all networks not used by at least one container

- all dangling images

- all build cache

- all unused network

-all volume docker system prune –a volume

Get real time events from the server docker system events

Display system-wide information docker system info

Show docker disk usage docker system df

container, edit, and update docker commit <conatainer id> <username/imagename>

delete an image from the local storage system docker rmi <image id>

-----------------------------------------------------------------------------------------------------------------------------------------------------
How to copy Docker images between hosts?
save the Docker image as a tar file
copy your image to a new system with regular file transfer tools
load the image into Docker
-----------------------------------------------------------------------------------------------------------------------------------------------------
Where Are Docker Logs Stored by Default?
/var/lib/docker/containers/[container-id]/[container-id] -[Link].
-----------------------------------------------------------------------------------------------------------------------------------------------------
Like using volumes what are the otherways to handle persistent data in containers?
Docker provides three ways to mount data to the container: volumes, bind mounts, and tmpfs storage
 Volumes are part of the host filesystem, but managed by docker at the specific path and should not be modified by
other applications
 Bind mounts can be anywhere on the host, but can be modified by other applications
 tmpfs are in the host's in-memory space, and never get written into the filesystem.
-----------------------------------------------------------------------------------------------------------------------------------------------------
How to start Containers that will run as user with normal Privileges and not as Root user?
Add user to Docker group
To run Docker as a non-root user, you have to add your user to the Docker group.
Create a docker group if there isn’t one:
$ sudo groupadd docker
Add your user to the docker group:
$ sudo usermod -aG docker [non-root user]
Using DockerFile
 RUN useradd -u 8877 john
 USER john
 verify the current user of our container using the id command in a docker run subcommand
 sudo docker run --rm nonrootimage id
-----------------------------------------------------------------------------------------------------------------------------------------------------
How to list the Docker layers of a Container?
You can view the contents of each layer on the Docker host at /var/lib/docker/aufs
The /var/lib/docker/aufs directory points to three other directories: diff, layers and mnt.
 Image layers and their contents are stored in the diff directory.
 How image layers are stacked is in the layer’s directory.
 Running containers are mounted below the mnt directory (more explained below about mounts).
-----------------------------------------------------------------------------------------------------------------------------------------------------
How to list the containers that exit before last 10 minutes?
docker ps -a --filter 'exited=0' | awk '{print $1 " " $8 " " $9 " " $10 " " $11 " " $12 }' | grep "weeks \| days \| hours \| hour "
-----------------------------------------------------------------------------------------------------------------------------------------------------
How would you transfer data from one container into another?
First of all, copy file to some temporary directory on the host using docker cp
Then transfer it from the temp directory to the other container using docker exec
-----------------------------------------------------------------------------------------------------------------------------------------------------
What is Docker interlock
Interlock is an application routing proxy service for Docker.
-----------------------------------------------------------------------------------------------------------------------------------------------------
What are the types of Docker networks?
Docker offers a mature networking model. There are three common Docker network types –
Bridge networks used within a single host,
Overlay networks used for multi-host communication,
macvlan networks are used to connect Docker containers directly to host network interfaces.
-----------------------------------------------------------------------------------------------------------------------------------------------------
What are the basic parameter used in Docker compose?
Version
Service
Network
Volume
-----------------------------------------------------------------------------------------------------------------------------------------------------
What is the lifecycle of a Docker Container?
This is one of the most popular questions asked in Docker interviews. Docker containers have the following lifecycle:
 Create a container
 Run the container
 Pause the container(optional)
 Un-pause the container(optional)
 Start the container
 Stop the container
 Restart the container
 Kill the container
 Destroy the container
-----------------------------------------------------------------------------------------------------------------------------------------------------
Explain in detail about the Dockers file system? What is UFS?Also explain about the snapshotting FS and VFS and
their use case scenarios.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Docker Networking

You might also like