The Builder

Docker

  1. docker ps
  2. docker ps -a
  3. docker images
  4. docker pull ubuntu
  5. docker run ubuntu
  6. docker run -it ubuntu /bin/bash
  7. docker stop <container_id>
  8. docker start <container_id>
  9. docker restart <container_id>
  10. docker rm <container_id>
  11. docker rmi <image_id>
  12. docker exec -it <container_id> /bin/bash
  13. docker logs <container_id>
  14. docker inspect <container_id>
  15. docker build -t myapp .
  16. docker run -d myapp
  17. docker commit <container_id> mynewimage
  18. docker tag myapp:latest myrepo/myapp:1.0
  19. docker push myrepo/myapp:1.0
  20. docker pull myrepo/myapp:1.0
  21. docker network ls
  22. docker network create mynetwork
  23. docker network connect mynetwork <container_id>
  24. docker network disconnect mynetwork <container_id>
  25. docker volume create myvolume
  26. docker volume ls
  27. docker volume rm myvolume
  28. docker cp <container_id>:/path/to/file /local/path
  29. docker cp /local/path <container_id>:/path/to/file
  30. docker stats <container_id>
  31. docker top <container_id>
  32. docker rename <container_id> new_name
  33. docker history <image_id>
  34. docker diff <container_id>
  35. docker pause <container_id>
  36. docker unpause <container_id>
  37. docker system prune -f
  38. docker image prune -f
  39. docker container prune -f
  40. docker events
  41. docker save myimage > myimage.tar
  42. docker load -i myimage.tar
  43. docker login
  44. docker logout
  45. docker system df
  46. docker export <container_id> > mycontainer.tar
  47. docker import mycontainer.tar
  48. docker search ubuntu
  49. docker inspect --format='{{.NetworkSettings.IPAddress}}' <container_id>
  50. docker run -p 8080:80 myapp

  1. Start a container with a specific image
    docker run ubuntu

  2. Run an image in interactive mode with a shell
    docker run -it ubuntu /bin/bash

  3. Run a container in the background
    docker run -d ubuntu

  4. Run a container with a custom name
    docker run --name mycontainer ubuntu

  5. Run a container and automatically remove it when stopped
    docker run --rm ubuntu

  6. Run a container with a specified command
    docker run ubuntu echo "Hello, Docker!"

  7. Run a container with an environment variable
    docker run -e MY_ENV_VAR=value ubuntu

  8. Run a container with multiple environment variables
    docker run -e VAR1=value1 -e VAR2=value2 ubuntu

  9. Run a container with a custom hostname
    docker run --hostname myhostname ubuntu

  10. Run a container with limited CPU usage
    docker run --cpus="1.5" ubuntu

  11. Run a container with limited memory
    docker run -m 512m ubuntu

  12. Run a container and map a host port to the container
    docker run -p 8080:80 nginx

  13. Run a container with a custom network
    docker run --network mynetwork ubuntu

  14. Run a container and link it to another container
    docker run --link othercontainer:alias ubuntu

  15. Run a container with a specified user
    docker run -u 1001 ubuntu

  16. Run a container and mount a host directory
    docker run -v /host/path:/container/path ubuntu

  17. Run a container in privileged mode
    docker run --privileged ubuntu

  18. Run a container with read-only root filesystem
    docker run --read-only ubuntu

  19. Run a container with restart policy (always)
    docker run --restart always ubuntu

  20. Run a container with restart policy (on-failure)
    docker run --restart on-failure ubuntu

  21. Run a container with log driver set to JSON
    docker run --log-driver json-file ubuntu

  22. Run a container and specify the PID namespace
    docker run --pid=host ubuntu

  23. Run a container with custom DNS
    docker run --dns 8.8.8.8 ubuntu

  24. Run a container with a specific MAC address
    docker run --mac-address="02:42:ac:11:65:43" ubuntu

  25. Run a container with security options
    docker run --security-opt seccomp=unconfined ubuntu

  26. Run a container with specific working directory
    docker run -w /app ubuntu

  27. Run a container with limited I/O bandwidth
    docker run --device-write-bps /dev/sda:1mb ubuntu

  28. Run a container and expose a specific port
    docker run -P -d nginx

  29. Run a container and specify a custom entrypoint
    docker run --entrypoint /my-script.sh ubuntu

  30. Run a container and specify both entrypoint and command
    docker run --entrypoint /bin/cat ubuntu /etc/hosts

  31. Run a container and join an existing network namespace
    docker run --network container:<container_id> ubuntu

  32. Run a container in detached mode and log stdout to a file
    docker run -d ubuntu > mylog.txt

  33. Run a container with a health check
    docker run --health-cmd="curl --fail http://localhost || exit 1" ubuntu

  34. Run a container in a custom IPC mode
    docker run --ipc=host ubuntu

  35. Run a container and give it additional capabilities
    docker run --cap-add=NET_ADMIN ubuntu

  36. Run a container with limited number of open files
    docker run --ulimit nofile=1024:1024 ubuntu

  37. Run a container with specific stop signal
    docker run --stop-signal SIGUSR1 ubuntu

  38. Run a container with limited swap memory
    docker run -m 512m --memory-swap 1g ubuntu

  39. Run a container with a device mounted
    docker run --device=/dev/sda:/dev/xvdc ubuntu

  40. Run a container in detached mode and attach later
    docker run -d --name myapp ubuntu && docker attach myapp

  41. Run a container and set its init process
    docker run --init ubuntu

  42. Run a container with a custom group ID
    docker run --group-add 1001 ubuntu

  43. Run a container with restricted read and write permissions
    docker run -v /host/path:/container/path:ro ubuntu

  44. Run a container with CPU shares to prioritize
    docker run --cpu-shares 512 ubuntu

  45. Run a container with specific hostname and domain name
    docker run --hostname myhost --domainname mydomain ubuntu

  46. Run a container with a custom label
    docker run --label env=dev ubuntu

  47. Run a container in interactive mode with automatic reattach
    docker run --interactive --tty --detach-keys="ctrl-c" ubuntu

  48. Run a container with a custom cgroup parent
    docker run --cgroup-parent /docker ubuntu

  49. Run a container and use sysctl settings
    docker run --sysctl net.ipv4.ip_forward=1 ubuntu

  50. Run a container and log to specific log driver
    docker run --log-driver=fluentd ubuntu


  1. List running containers
    docker ps

  2. List all containers, including stopped ones
    docker ps -a

  3. Start a stopped container
    docker start <container_id>

  4. Stop a running container
    docker stop <container_id>

  5. Restart a container
    docker restart <container_id>

  6. Remove a stopped container
    docker rm <container_id>

  7. Force remove a running container
    docker rm -f <container_id>

  8. Rename a container
    docker rename <old_name> <new_name>

  9. Inspect a container’s details
    docker inspect <container_id>

  10. View container logs
    docker logs <container_id>

  11. Follow live logs of a container
    docker logs -f <container_id>

  12. View the top processes in a container
    docker top <container_id>

  13. Run a command in a running container
    docker exec -it <container_id> /bin/bash

  14. Copy a file from container to host
    docker cp <container_id>:/path/in/container /path/on/host

  15. Copy a file from host to container
    docker cp /path/on/host <container_id>:/path/in/container

  16. Pause a container
    docker pause <container_id>

  17. Unpause a paused container
    docker unpause <container_id>

  18. List all paused containers
    docker ps --filter "status=paused"

  19. Get container stats (CPU, memory, etc.)
    docker stats <container_id>

  20. Change a container’s resource limits
    docker update --cpus="1.5" --memory="512m" <container_id>

  21. Limit the number of restart attempts
    docker update --restart=on-failure:3 <container_id>

  22. Attach to a running container
    docker attach <container_id>

  23. Detach from a container without stopping it
    docker attach --detach-keys="ctrl-c" <container_id>

  24. Check container health status
    docker inspect --format='{{json .State.Health.Status}}' <container_id>

  25. List containers by name filter
    docker ps -f "name=mycontainer"

  26. List containers by status filter
    docker ps -f "status=exited"

  27. List containers based on label
    docker ps --filter "label=env=prod"

  28. Get the container’s IP address
    docker inspect --format='{{.NetworkSettings.IPAddress}}' <container_id>

  29. Change container restart policy to always
    docker update --restart=always <container_id>

  30. Kill a container (send SIGKILL)
    docker kill <container_id>

  31. Kill a container with a custom signal
    docker kill --signal="SIGUSR1" <container_id>

  32. Remove all stopped containers
    docker container prune -f

  33. Remove containers older than 24 hours
    docker container prune --filter "until=24h"

  34. List containers sorted by size
    docker ps --size --sort=size

  35. List containers in JSON format
    docker ps -a --format "{{json .}}"

  36. List containers showing only IDs
    docker ps -q

  37. Show the last created container
    docker ps -l

  38. Show the most recent container logs
    docker logs $(docker ps -q -n 1)

  39. Limit logs to last 10 lines
    docker logs --tail 10 <container_id>

  40. Remove all exited containers
    docker rm $(docker ps -q -f "status=exited")

  41. Restart all containers
    docker restart $(docker ps -q)

  42. Stop all running containers
    docker stop $(docker ps -q)

  43. Display containers grouped by image
    docker ps --filter ancestor=nginx

  44. Show the container’s start time
    docker inspect -f '{{.State.StartedAt}}' <container_id>

  45. Export a container’s filesystem to a .tar file
    docker export <container_id> > container_backup.tar

  46. Import a saved container .tar file
    docker import container_backup.tar

  47. Limit a container’s file descriptors
    docker update --ulimit nofile=1024:1024 <container_id>

  48. Set the container’s stop timeout
    docker update --stop-timeout 30 <container_id>

  49. Assign a container to a new network
    docker network connect mynetwork <container_id>

  50. Disconnect a container from a network
    docker network disconnect mynetwork <container_id>

Tags: