Docker Commands - samruddhipatil12/wiki-pages GitHub Wiki

1.Difference between docker image save and docker container export

docker image save:

  • What it does: Saves a Docker image as a tarball file.
  • When to use it: When you want to back up or transfer an image to another system.
  • Example: You have an image called myapp:latest and you want to save it to a file named myapp.tar.
  • Command: docker image save -o myapp.tar myapp:latest

docker container export:

  • What it does: Exports the filesystem of a container as a tarball file.
  • When to use it: When you want to save the state of a running or stopped container, including any changes made inside the container.
  • Example: You have a running container with ID abc123 and you want to export its filesystem to a file named container.tar.
  • Command: docker container export -o container.tar abc123

2.Difference between docker image rm and docker image prune

docker image rm:

  • What it does: Removes one or more specified Docker images.
  • When to use it: When you want to delete specific images you no longer need.
  • Example: You have an image called myapp:latest and you want to remove it.
  • Command: docker image rm myapp:latest

docker image prune:

  • What it does: Removes all unused Docker images (images that are not currently used by any containers).
  • When to use it: When you want to clean up your system by removing images that are not in use, to free up space.
  • Example: You want to remove all dangling images.
  • Command: docker image prune

3.Difference between docker container stop and docker container kill

docker container stop:

  • What it does: Gracefully stops a running container by sending a SIGTERM signal, allowing the container to finish its work and shut down properly.
  • When to use it: When you want to stop a container and give it a chance to clean up.
  • Example: You have a running container with ID abc123 and you want to stop it.
  • Command: docker container stop abc123

docker container kill:

  • What it does: Immediately stops a running container by sending a SIGKILL signal, forcing it to terminate abruptly.
  • When to use it: When you need to stop a container immediately, without waiting for it to clean up.
  • Example: You have a running container with ID abc123 and you need to force it to stop right away.
  • Command: docker container kill abc123

4.Difference between docker container pause and docker container stop

docker container pause:

  • What it does: Pauses all processes within a running container.
  • When to use it: When you want to temporarily halt the activity of a container without stopping it.
  • Example: You have a running container with ID abc123 and you want to pause it.
  • Command: docker container pause abc123

docker container stop:

  • What it does: Gracefully stops a running container.
  • When to use it: When you want to stop the container completely and allow it to shut down properly.
  • Example: You have a running container with ID abc123 and you want to stop it.
  • Command: docker container stop abc123

Difference between docker container unpause and docker container start

docker container unpause:

  • What it does: Resumes the processes within a paused container.
  • When to use it: When you want to continue the activity of a paused container.
  • Example: You have a paused container with ID abc123 and you want to unpause it.
  • Command: docker container unpause abc123

docker container start:

  • What it does: Starts a stopped container.
  • When to use it: When you want to start a container that is not running.
  • Example: You have a stopped container with ID abc123 and you want to start it.
  • Command: docker container start abc123