Docker for DevOps Engineers.

·

2 min read

Table of contents

No heading

No headings in the article.

Docker

Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.

Tasks

  1. Use the docker run command to start a new container and interact with it through the command line.
  • docker run command is used to create a new container.

  • command - docker run -d <image-name or ID> here -d is a detached mode

  • To create a container with a container name:

  • command - docker run -d --name <container-name> <image-name>

  • To create a container with a port number:

  • command - docker run -d -p 8080:80 <image-name>

  • Create a container with a name and port number:

  1. Use the docker inspect command to view detailed information about a container or image.

docker inspect is a command that returns detailed, low-level information on Docker objects. Those objects can be docker images, containers, networks, volumes, plugins, etc. By default, docker inspect returns information in JSON format.

  1. Use the docker port command to list the port mappings for a container.

command - docker port <container-name>

docker port Container-name [PRIVATE_PORT[/PROTO]]

  1. Use the docker stats command to view resource usage statistics for one or more containers.

docker stats: The docker stats command returns a live data stream for running containers. To limit data to one or more specific containers, specify a list of container names or ids separated by a space. You can specify a stopped container but stopped containers do not return any data.

command: docker stats

command - docker stats [options] [containers...]

Options:

  • --all, -a: Show all containers (default shows just running)

  • --format: Pretty print images using a Go template

  • --no-stream: Disable streaming stats and only pull the first result

  • --no-trunc: Do not truncate output

  1. Use the docker top command to view the processes running inside a container.

docker top: Display the running processes of a container.

command: docker top <container>

6. Use the docker save command to save an image to a tar archive.

docker save: Save one or more images to a tar archive

command: docker save [options] [image]

option: --output, -o: Write to a file, instead of STDOUT

7. Use the docker load command to load an image from a tar archive.

command: docker load [options]

options:

  • --input, -i: Read from the tar archive file, instead of STDIN

  • --quiet, -q: Suppress the load output

Thank you for reading!