You are currently viewing Docker commands that every Data Scientist Should know

Docker commands that every Data Scientist Should know

Basic docker Commands

  • docker –version: Displays the version of Docker currently installed on your machine. This is useful for checking that you have the right version of Docker installed.
  • docker  info: Information about your Docker installation at the system level is provided by the docker info command. All the pieces of your Docker infrastructure are represented here, from containers and images to storage drivers and more.
  • docker –help: This command provides guidance and a rundown of all Docker commands. If you need immediate assistance or simply want to see what Docker is capable of, this is the command to type.
  • docker run IMAGE: It will start a container using that image. This command is critical for running software in a contained environment.
  • docker  pull  IMAGE: A Docker image can be downloaded from a container registry using the docker pull IMAGE command. Containers can be thought of as buildings; to deploy one, the first step is to pull its blueprint, or image.
  • docker  images: It returns a list of all the local Docker images. It helps you organise your personal collection of images by listing their names, IDs, and sizes.
  • docker ps: It shows a rundown of all containers that are currently active. The status of running containers can be tracked with the help of this command.
  • docker ps -a: It will display a list of running and halted containers. You can monitor both active and inactive containers with this command, which is useful for management and cleanup.
  • docker stop CONTAINER: It will pause an active container so that its processes can be gracefully terminated.
  • docker start CONTAINER: It will restart a container that had previously stopped. If you’ve previously stopped a container and want to start it up again, use this command.
  • docker restart CONTAINER: A container is completely restarted by using this command.
  • docker pause CONTAINER: To temporarily halt all activity in a container.
  • docker unpause CONTAINER: Restarts a container that was previously paused with this command.
  • docker  rm  CONTAINER: To get rid of a container that has been stopped. When a container is no longer needed, this is what you use to clear it up.
  • docker  rmi  IMAGE: A Docker image can be removed from your local repository with the command docker rmi IMAGE. Remove unnecessary or out-of-date pictures using this handy tool.
  • docker search TERM: Doing a docker search phrase will look for results for that phrase in Docker Hub (the default registry). It facilitates the process of locating photographs that may be used with numerous programmes and services.
  • docker  logs  CONTAINER: It shows the logs for that container will be seen. This is really helpful when trying to analyse and fix issues with containerized apps.
  • docker exec -it CONTAINER COMMAND: Executes an external command within a container using the docker exec -it option. Accessing the container’s shell in this way is helpful for troubleshooting and running ad hoc commands.
  • docker  build  -t  IMAGE:TAG  PATH: To create a Docker image from the Dockerfile at the given path. The generated image can be given a name and, optionally, a tag with the -t flag.
  • docker  build  -t  IMAGE:TAG  PATH: To make a locally-stored Docker image available to the wider Docker community. When you want to show off your personalised graphics, this is a must.
  • docker  push  IMAGE:TAG: It retrieves an image from a Docker registry based on a given tag. This is helpful if you need to grab a specific image version for your containers.
  • docker  commit  CONTAINER  NEW_IMAGE: you can save a snapshot of the current state of a container as a new image. Useful for creating a fresh image from the contents of a container after making edits.
  • docker  network  ls: It is used to see a list of all the Docker networks installed on your computer. Connectivity and isolation management between containers rely heavily on networks.
  • docker  volume  ls: It show all of the Docker volumes currently mounted on your computer. Data stored in a volume is persistent even if the volume’s container is deleted.
  • docker  version: It is used to displays comprehensive information about the version of Docker currently installed on your system, including client and server versions, build IDs, and more.
  • docker  login: This command grants access to a Docker registry, letting you safely upload and download images.
  • docker  logout: It will log you out of all Docker services. This is a crucial security measure since it prevents unnecessary storage of your credentials.
  • docker run -d IMAGE: Launches a container in detached mode, in the background. This is helpful for deploying containers as services, as they may then function independently of the user’s terminal window.
  • docker  run  -p  HOST_PORT:CONTAINER_PORT  IMAGE: A port can be mapped from the host system to the container with this command. This opens up the container’s internal services to the outside world.
  • docker  run  -v  HOST_DIR:CONTAINER_DIR  IMAGE: Mount a volume on the host inside the container with this command. This is necessary for keeping any settings, configurations, or assets alive through container restarts.
  • docker stats: Gives you data in real time on how your containers are consuming system resources. You may track metrics like CPU utilisation, memory footprint, and network I/O to keep tabs on container efficiency.
  • docker top CONTAINER: It will show you what processes are currently executing inside a container and how much of its resources they are using.
  • docker  inspect  CONTAINER/IMAGE: Obtain exact details regarding a container or image with the help of this command. This provides a comprehensive look at the container’s information, including configuration, network settings, volumes, and more.
  • docker events: Real-time monitoring of Docker events, with details on container and image lifecycle events. It helps you keep tabs on what’s going on in your Docker environment and when.
  • docker  rename  OLD_NAME  NEW_NAME: This is useful for keeping a standardised naming scheme or changing the names of containers.
  • docker  cp  CONTAINER:SRC_PATH  DEST_PATH: Copies files from a container to the local filesystem using this command. Without this, it would be impossible to transfer data to and from containers without using network services.
  • docker-compose  up: Launches services specified in a docker-compose.yml configuration file. By letting you specify complicated services and their configurations in a single file, Docker Compose streamlines the management of multi-container systems.
  • docker-compose  down: Containers specified in a docker-compose.yml file are stopped and removed when you run docker-compose down. It’s useful for post-service cleanup because of this.
  • docker-compose  ps: It displays a list of containers together with their current states (running, stopped, etc.) and any additional data specified in the docker-compose.yml configuration file.
  • docker-compose  logs:: It shows activity for services under its control. This is helpful for monitoring and troubleshooting apps that are deployed across several Docker containers using Docker Compose.
  • docker  system  df: Displays disc consumption in relation to Docker resources with the help of df on your system (docker system). Space utilisation data for containers, pictures, volumes, and networks can be retrieved via this tool.
  • docker  system  prune: With this command, inactive resources like containers, images, and volumes are removed. Deleting unnecessary components helps clean the system and make more room on the hard drive.
  • docker  system  prune  -a: To delete everything in your Docker environment, regardless of its current state, use the docker system prune -a command. Caution is advised before using this, as it will completely remove Docker from your machine.

Intermediate Docker Commands

  • docker  history  IMAGE: It will show you what commands and layers went into making that image. Helpful for tracing an image’s history and improving the creation process.
  • docker  inspect  –format=”{{.NetworkSettings.IPAddress}}” CONTAINER: To get the IP address for a container, this command. When talking to a container that is already up and running, this command is invaluable.
  • docker exec -u USER CONTAINER COMMAND: You can execute a command inside a container with the permissions of that user. Benefits container-level security and access management.
  • docker run -e KEY=VALUE IMAGE: Setting runtime environment variables in a container with this command. Applications can be set up in the container without needing to make any changes to their source code or configuration files.
  • docker  run  –rm  IMAGE: This command automatically remove the container when it exists. This is useful for one-time or throwaway projects, since the container is then discarded once the work is done.
  • docker  build  –build-arg  KEY=VALUE  -t  IMAGE:TAG  PATH: This command allows you to tailor the build process for a specific Dockerfile. This facilitates dynamic configuration while making an image.
  • docker  push  REGISTRY/IMAGE:TAG: It uploads a local image to a user-defined registry so that it can be used in other settings or by other people.
  • docker  pull  REGISTRY/IMAGE:TAG: It is used to retrieve an image from a private registry. When working with photos from private or specialised repositories, this is a must.
  • docker  login  REGISTRY: This command logs a user in with their own private registry. Required for safe, private image and data storage access.
  • docker  tag  SOURCE_IMAGE:TAG  TARGET_IMAGE:TAG: To allow the same image to be referred to by different names and versions. Helpful for maintaining different iterations of photos.
  • docker  volume  create  VOLUME: You can make a new, persistent storage space for containers with a custom name. Data that must survive a container restart or removal must be stored on a volume.
  • docker  volume  inspect  VOLUME: To get specifics about a volume, such as its settings and mount point. Helpful for checking volume levels and listening habits.
  • docker  network  create  NETWORK: This command sets up a private network for containers to use for encrypted communication. Applications can be compartmentalised and network traffic between containers can be managed with the use of custom networks.
  • docker  network  inspect  NETWORK: A network’s setup and list of associated containers are displayed in great detail when you use this command. For solving network problems, this is a must-have.
  • docker  network  connect  NETWORK  CONTAINER: To establish connection between containers on the same network. Facilitates the development of connected services.
  • docker  network  disconnect  NETWORK  CONTAINER: To isolate a container from others on the same network. For safety or organisational purposes, this is useful.
  • docker-compose  -f  FILE  up: Launches the services specified in the given docker-compose.yml file using the docker-compose command line interface. Docker Compose streamlines the process of managing apps that span several containers by letting you define and launch them with a single command.
  • docker-compose  -f  FILE  down: Containers specified in the given docker-compose.yml file will be shut down and removed when you run this command. This command removes clutter from the system by shutting down unnecessary processes.
  • docker-compose  -f  FILE  ps: This will list the containers that Docker Compose is managing for a given docker-compose.yml file, giving you a high-level view of the configurations and states of your services.
  • docker-compose  -f  FILE  logs: Docker Compose logs for a given docker-compose.yml file can be viewed with this command. This is quite helpful for service troubleshooting and monitoring in multi-container environments.
  • docker-compose  -f  FILE  build: Builds the services specified in the given docker-compose.yml file using the –file flag. When making changes to the configuration or Dockerfiles, this command is used to force a rebuild of the service.
  • docker save -o OUTPUT_FILE IMAGE: To store an image in a tarball. The images contained in this tarball can be easily transferred to and used in a different Docker installation.
  • docker  load  -i  INPUT_FILE: Loads an image from the tarball file named INPUT_FILE. To make images accessible for container deployment in Docker, this command is used to import them.
  • docker export CONTAINER > OUTPUT_FILE: A container’s filesystem can be exported to the tarball file named OUTPUT_FILE with the docker export CONTAINER command. This is helpful for transferring the contents of a container across systems or archiving its current state.
  • docker  import  INPUT_FILE: It will create a new image from the filesystem that was exported from a container. It’s possible to recycle previously exported containers by converting them back into Docker images.
  • docker attach CONTAINER: This command links up with a container’s operating I/O streams (STDIN, STDOUT, and STDERR). When working with processes inside a container, this is a helpful feature to have.
  • docker pause $(docker ps -q): It will halt all containers currently operating. The container processes can be temporarily stopped using this command.
  • docker unpause $(docker ps -q): To resume running containers that were previously halted.
  • docker kill CONTAINER: This command terminates a container by sending it the SIGKILL signal. If a shipping container does not respond to the standard stop signal, use this instruction.
  • docker  wait  CONTAINER: When a container is stopped using docker wait CONTAINER, the exit code is displayed. This can be used to coordinate the execution of a process or script with the termination of a container.
  • docker  logs  –tail  N  CONTAINER: By using this command, you can see the most recent N lines of a container’s logs, which is useful for debugging and monitoring.
  • docker  ps  -q  -f  status=exited: This command provides a useful list of recently terminated containers, making it useful for scripting or automation.
  • docker  system  prune  -f: Forcibly removes any unnecessary data, such as halted containers, unused networks, dangling images, and volumes. If you want to do a complete housecleaning of your Docker installation, use this command.
  • docker system events: Receives updates on container and image activity directly from the Docker server in near real-time. This is helpful for keeping tabs on the Docker ecosystem and tracking any alterations that have been made.
  • docker  system  df  -v: Using this command, you can see how much space Docker is taking up on your hard drive. Space utilisation details for containers, pictures, volumes, and networks can be viewed in fine detail.
  • docker  plugin  install  PLUGIN: Using this command, you can add new features and capabilities to Docker. Using plugins, you can easily add new functionality to the Docker environment.
  • docker  plugin  ls: Lists all Docker plugins with their names, IDs, and current states using the docker plugin ls command. This facilitates the monitoring and management of active plugins.
  • docker  plugin  disable  PLUGIN: Disables a specific Docker plugin, making it unavailable to containers and services with the docker plugin deactivate PLUGIN command. This is helpful for temporarily disabling plugins without having to delete them.
  • docker  plugin  enable  PLUGIN: This command activates a dormant Docker plugin so that containers and services can once again make use of it. Useful for enabling plugins again after temporarily disabling them.
  • docker  plugin  upgrade  PLUGIN: Using this command, you can update a plugin so that it works with the newest version of Docker. This is crucial for preserving the reliability and safety of plugins.
  • docker  plugin  remove  PLUGIN: Using this command, you can uninstall a Docker plugin and free up its associated data and settings. When a plugin is no longer needed, you can uninstall it with this command.
  • docker  swarm  init: Initialises a Docker swarm, forming a group of Docker nodes that may be controlled collectively through the use of the docker swarm init command. Activating Docker swarm mode begins with this.
  • docker  swarm  join: With docker swarm join, a node can become a worker or a manager in an already-established Docker swarm. Swarms of nodes work together to deliver an extremely scalable and reliable infrastructure on which to run programmes.
  • docker  swarm  leave: The command tells a node to stop participating in the Docker swarm. Nodes can be removed from the swarm cluster in a controlled manner using this method.
  • docker  swarm  update: A current Docker swarm’s configuration can be upgraded with a simple command: docker swarm update. Using this command, you can adjust the swarm’s configuration to better suit your needs.
  • docker service create: Doing a docker service create within a Docker swarm will produce a whole new service. Scalable and distributed applications can be deployed with the help of swarm clusters, and services define the tasks that should be conducted on the cluster.
  • docker service scale: Using the current number of replicas (tasks), docker service scale can increase or decrease the capacity of a service. With this command, you may easily adjust the swarm’s instance count for a given service.
  • docker  service  inspect: Doing a docker service inspect returns information on a service’s configuration, replicas, and networking in a Docker swarm.
  • docker service ps: Using this command, you can see which containers belong to a certain service in a Docker cluster. This command displays information about the services being provided by the nodes in the swarm and their current condition.
  • docker  service  logs: This command will fetch the service’s logs from the Docker cluster. This is helpful for monitoring and debugging swarm cluster services.
  • docker  stack  deploy: Doing a “docker stack deploy” will either deploy a new stack to the Docker swarm or update an existing stack. Stacks are used to control several infrastructure components, such as services, networks, and volumes, with a single programme.
  • docker stack ls: To get an overview of the applications that have been deployed and their current settings, you can use the docker stack ls command.
  • docker  stack  rm: Removes a stack from the Docker swarm, together with its associated services, tasks, and resources, using the docker stack rm command.
  • docker stack services: This command will list the Docker swarm services belonging to a certain stack, including details such as replicas, ports, and configurations.
  • docker stack ps: This command will displays a list of the containers and their associated IDs and services within a given stack in a Docker swarm.
  • docker secret create: This command generates a new secret, a safe place to save information like API keys and passwords. Services within the swarm have access to the encrypted secrets.
  • docker secret ls: Lists all secrets in the Docker swarm, including their IDs and names, with the docker secret ls command. This is a useful command for keeping track of confidential information.

Advance docker Commands

  • docker  save  IMAGE:TAG  -o  FILE: To store a Docker image with a particular tag in a file. Using this command, photos can be safely stored and transferred across computers.
  • docker  load  -i  FILE: To restore a Docker image that was previously saved with docker save, use the docker load -i FILE command. Restoring an image with this command makes it suitable for docker operations once again.
  • docker  manifest: Container images with support for several architectures can be created and pushed with the help of docker manifest.
  • docker  manifest  inspect: Doing a docker manifest inspect on a multi-architecture image manifest will show you all the layers and architectures that are supported.
  • docker  manifest  push: Doing a docker manifest push uploads an image manifest that supports several architectures to a registry, allowing for their dissemination.
  • docker  buildx: Create and distribute images for multiple platforms using the familiar docker build command. This is a great tool for making graphics that can run on multiple CPU types.
  • docker  run  -d  –restart=unless-stopped  IMAGE: Launches a container in detached mode with the “unless-stopped” restart policy using the docker run command. Unless the user intervenes, the container will restart itself at regular intervals.
  • docker  run  –init  IMAGE: Launches a container with an init process, as in docker run –init IMAGE. This ensures that signals are handled correctly and that processes within the container can be gracefully terminated.
  • docker  cp  SRC_PATH  CONTAINER:DEST_PATH: Copies files or directories from the host machine to an active container using the docker cp SRC_PATH CONTAINER:DEST_PATH command. This command makes it easier for the host and containers to share information.
  • docker exec -it CONTAINER sh: Doing something like docker exec -it CONTAINER sh will launch an interactive shell session within the currently operating container, letting you access its files and run commands with full root privileges.
  • docker  diff  CONTAINER: This command will display any new, updated, or removed files within a container’s filesystem. To monitor changes inside a container, use this command.
  • docker  logs  -f  CONTAINER: The output of a container can be monitored in real time using docker logs -f CONTAINER. The -f option causes the log to be displayed in real time.
  • docker  network  create  –driver  overlay  NETWORK: To make an overlay network for Docker swarm services, run docker network create with the –driver overlay NETWORK option. Using overlay networks, services can talk to one another over individual swarm nodes.
  • docker  network  create  –driver  macvlan  NETWORK: Docker’s MACVLAN network creation command, “docker network create –driver macvlan NETWORK,” generates isolated networks for containers on the host system. This is helpful for adding containers to an already established network.
  • docker  network  create  –driver  bridge  NETWORK: Docker’s NETWORK command, when run with the –driver bridge option, sets up a local bridge network for containers running on the same host. Bridge networks are best suited for private, intra-company settings.
  • docker  network  create  –driver  host  NETWORK: Create Doing a docker network create with the driver set to “host” makes it so containers may access the host’s network. Network settings for containers on the host system are the same as those for the host system.
  • docker  network  inspect  –format  ‘{{json  .Containers}}’  NETWORK: The command docker network inspect –format “json.Containers” NETWORK returns a JSON file containing a list of all containers on the specified network. This gives you specifics on the containers that are connected to the given network.
  • docker-compose config: This command verifies the combined Docker Compose configuration from several files and displays the results. This is helpful before releasing services to ensure the configuration is accurate.

Conclusion

In this blog, we have learned about various docker commands from basic to advance.

If you like this blog, you can share it with your friends or colleague. You can connect with me on social media profiles like Linkedin, Twitter, and Instagram.

Linkedin – https://www.linkedin.com/in/abhishek-kumar-singh-8a6326148

Twitter- https://twitter.com/Abhi007si

Instagram- www.instagram.com/dataspoof