Part II: Docker Commands
1. Copy files/folders: Yes, we can copy files/folders from local machine to container and vice versa. To copy directories recursively use cp -a command. Applying the container’s / (root) directory is optional.
docker cp <container_name/id>:<source_path> <destination_path_of_localsystem> docker cp <source_path_of_localsystem> <container_name/id>:<destination_path>
2. Docker Commit: Using docker commit we can create docker image from docker container. Using different options we can commit containers with new configurations.
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] docker commit <container_name> <image_name>:<tag>
3. Docker tag: Docker tag command is useful to assign another name to an existing image for reference. It creates an alias by the name of the TARGET_IMAGE that refers to the SOURCE_IMAGE.
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
4. Docker diff: To check changes in file or directory from the container file system. Three different types to track the changes. A represents any file or directory added, C is for if any file or directory changes, and D for deletion of any file and directory as given below.
docker diff CONTAINER A /home/test C /root D /dev/data
5. Docker inspect: Docker inspect gives you detailed information on docker object in JSON format. With inspect, we can give container name/id or docker image/id. Using format option you can get formatted output.
docker inspect [OPTIONS] NAME|ID [NAME|ID...]
6. Docker port: To inspect the port mapping of docker containers, use docker port command. While working on container networking this command is usful to map port.
docker port CONTAINER [PRIVATE_PORT[/PROTO]] docker port test 65/tcp -> 0.0.0.0:22 5656/tcp -> 0.0.0.0:8080
7. Docker logs: Docker logs gives you a detailed log of docker container. Using different options like details, since, util etc you can get the log output.
docker logs [OPTIONS] CONTAINER
8. Docker history: Show the history of docker image. Using history command you can get how the docker image was built.
docker history [OPTIONS] IMAGE
9. Docker event: To get real-time events from docker server use event command as per per Docker object type. Here docker objects are containers, images, plugins, volumes, networks, daemons, nodes, services, secrets, configs. These docker objects report different events. To exit the docker events command, use CTRL+C.
docker events [OPTIONS]
10. Docker import: Used content from the tarball to create a filesystem docker image.
docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]] * Import the contents from a tarball to create a filesystem image
11. Docker export: Export a container’s filesystem as a tar archive.
docker export [OPTIONS] CONTAINER * Export a container's filesystem as a tar archive
12. Docker load: Load an image or repository from a tar archive. It restores both images and tags.
docker load [OPTIONS] docker load --input testimage.tar * Load an image from a tar archive or STDIN
13. Docker Save: Used save command to share or back up our image. Save one or more images to a tar archive. Contains all parent layers with all tagged versions. Using this command you can easily exchange docker images from one system to another system.
docker save [OPTIONS] IMAGE [IMAGE...] docker save testimage > testimage.tar * Save one or more images to a tar archive
14. Docker top: Shows the running processes of a container
docker top CONTAINER [ps OPTIONS]
15. Docker update: Docker update used for updates container configuration. This command is not supported for Windows containers. You can update the container's cpu-shares and memory to prevent containers from consuming too many resources.
docker update [OPTIONS] CONTAINER [CONTAINER...]
16. Docker Search: Search docker image from docker hub.
docker search image_name
17. Docker stats: Using stats command you can see live resource usage statistics for running containers.
docker stats [OPTIONS] [CONTAINER...]
Reference: For more details, you can check official Docker CLI commands.
Stay tuned for the most interesting topic Dockerfile !!!
PS: Please don't copy-paste this article. If you find it useful please feel free to share it, and yes don't forget to give credits.
DevOps |Platform Infrastructure | Systems Engineer
4 年Fantastic work
Full stack software engineer @ Digicert | Ex-SSE @ Thoughtworks | Persistent Systems | backend Dev | React | Tech Educator on YT & IG
4 年I learned a lot from your docker articles, thank you for sharing.