docker修改默认存储路径(有效)

查看当前docker的存储路径

docker info |grep Dir

关闭docker服务 sudo service docker stop sudo systemctl stop docker 将原有数据迁移至新目录

mkdir /path/docker -p

mv /var/lib/docker/* /path/docker/

修改docker.service配置文件,使用 —graph 参数指定存储位置

vim /usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd -H fd:// -containerd=/run/containerd/containerd.sock —graph /data/service/docker

重新加载配置文件

systemctl daemon-reload

systemctl start docker

systemctl enable docker
systemctl status docker

查看修改是否成功

docker info | grep Dir

docker

命令

  1. Usage: docker [OPTIONS] COMMAND
  2. A self-sufficient runtime for containers
  3. Options:
  4. --config string Location of client config files (default "/home/fcq/.docker")
  5. -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with
  6. "docker context use")
  7. -D, --debug Enable debug mode
  8. -H, --host list Daemon socket(s) to connect to
  9. -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
  10. --tls Use TLS; implied by --tlsverify
  11. --tlscacert string Trust certs signed only by this CA (default "/home/fcq/.docker/ca.pem")
  12. --tlscert string Path to TLS certificate file (default "/home/fcq/.docker/cert.pem")
  13. --tlskey string Path to TLS key file (default "/home/fcq/.docker/key.pem")
  14. --tlsverify Use TLS and verify the remote
  15. -v, --version Print version information and quit
  16. Management Commands:
  17. builder Manage builds
  18. config Manage Docker configs
  19. container Manage containers
  20. context Manage contexts
  21. engine Manage the docker engine
  22. image Manage images
  23. network Manage networks
  24. node Manage Swarm nodes
  25. plugin Manage plugins
  26. secret Manage Docker secrets
  27. service Manage services
  28. stack Manage Docker stacks
  29. swarm Manage Swarm
  30. system Manage Docker
  31. trust Manage trust on Docker images
  32. volume Manage volumes
  33. Commands:
  34. attach Attach local standard input, output, and error streams to a running container
  35. build Build an image from a Dockerfile
  36. commit Create a new image from a container's changes
  37. cp Copy files/folders between a container and the local filesystem
  38. create Create a new container
  39. deploy Deploy a new stack or update an existing stack
  40. diff Inspect changes to files or directories on a container's filesystem
  41. events Get real time events from the server
  42. exec Run a command in a running container
  43. export Export a container's filesystem as a tar archive
  44. history Show the history of an image
  45. images List images
  46. import Import the contents from a tarball to create a filesystem image
  47. info Display system-wide information
  48. inspect Return low-level information on Docker objects
  49. kill Kill one or more running containers
  50. load Load an image from a tar archive or STDIN
  51. login Log in to a Docker registry
  52. logout Log out from a Docker registry
  53. logs Fetch the logs of a container
  54. pause Pause all processes within one or more containers
  55. port List port mappings or a specific mapping for the container
  56. ps List containers
  57. pull Pull an image or a repository from a registry
  58. push Push an image or a repository to a registry
  59. rename Rename a container
  60. restart Restart one or more containers
  61. rm Remove one or more containers
  62. rmi Remove one or more images
  63. run Run a command in a new container
  64. save Save one or more images to a tar archive (streamed to STDOUT by default)
  65. search Search the Docker Hub for images
  66. start Start one or more stopped containers
  67. stats Display a live stream of container(s) resource usage statistics
  68. stop Stop one or more running containers
  69. tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  70. top Display the running processes of a container
  71. unpause Unpause all processes within one or more containers
  72. update Update configuration of one or more containers
  73. version Show the Docker version information
  74. wait Block until one or more containers stop, then print their exit codes
  75. Run 'docker COMMAND --help' for more information on a command.

例子

  • 删除
    • 容器
  1. docker rm -f 容器名/ID
  2. docker ps -a #查看所有容器
  3. docker rm -f `docker ps -a -q` # 删除所有容器
  1. - 镜像
  1. docker rmi -f image_name/ID
  2. docker images #查看所有镜像
  3. docker rmi -f `docker images -q` # 删除所有的镜像

docker pull

  1. Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]
  2. Pull an image or a repository from a registry
  3. Options:
  4. -a, --all-tags Download all tagged images in the repository
  5. --disable-content-trust Skip image verification (default true)
  6. --platform string Set platform if server is multi-platform capable
  7. -q, --quiet Suppress verbose output

docker run

  1. Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
  2. Run a command in a new container
  3. Options:
  4. --add-host list Add a custom host-to-IP mapping (host:ip)
  5. -a, --attach list Attach to STDIN, STDOUT or STDERR
  6. --blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
  7. --blkio-weight-device list Block IO weight (relative device weight) (default [])
  8. --cap-add list Add Linux capabilities
  9. --cap-drop list Drop Linux capabilities
  10. --cgroup-parent string Optional parent cgroup for the container
  11. --cidfile string Write the container ID to the file
  12. --cpu-count int CPU count (Windows only)
  13. --cpu-percent int CPU percent (Windows only)
  14. --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period
  15. --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
  16. --cpu-rt-period int Limit CPU real-time period in microseconds
  17. --cpu-rt-runtime int Limit CPU real-time runtime in microseconds
  18. -c, --cpu-shares int CPU shares (relative weight)
  19. --cpus decimal Number of CPUs 和--gpus 功能类似
  20. --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
  21. --cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
  22. -d, --detach Run container in background and print container ID
  23. --detach-keys string Override the key sequence for detaching a container
  24. --device list Add a host device to the container
  25. --device-cgroup-rule list Add a rule to the cgroup allowed devices list
  26. --device-read-bps list Limit read rate (bytes per second) from a device (default [])
  27. --device-read-iops list Limit read rate (IO per second) from a device (default [])
  28. --device-write-bps list Limit write rate (bytes per second) to a device (default [])
  29. --device-write-iops list Limit write rate (IO per second) to a device (default [])
  30. --disable-content-trust Skip image verification (default true)
  31. --dns list Set custom DNS servers
  32. --dns-option list Set DNS options
  33. --dns-search list Set custom DNS search domains
  34. --domainname string Container NIS domain name
  35. --entrypoint string Overwrite the default ENTRYPOINT of the image
  36. -e, --env list Set environment variables
  37. --env-file list Read in a file of environment variables
  38. --expose list Expose a port or a range of ports
  39. --gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs) gpu设备('all', '0','1'),
  40. --group-add list Add additional groups to join
  41. --health-cmd string Command to run to check health
  42. --health-interval duration Time between running the check (ms|s|m|h) (default 0s)
  43. --health-retries int Consecutive failures needed to report unhealthy
  44. --health-start-period duration Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s)
  45. --health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default 0s)
  46. --help Print usage
  47. -h, --hostname string Container host name
  48. --init Run an init inside the container that forwards signals and reaps processes
  49. -i, --interactive Keep STDIN open even if not attached
  50. --io-maxbandwidth bytes Maximum IO bandwidth limit for the system drive (Windows only)
  51. --io-maxiops uint Maximum IOps limit for the system drive (Windows only)
  52. --ip string IPv4 address (e.g., 172.30.100.104)
  53. --ip6 string IPv6 address (e.g., 2001:db8::33)
  54. --ipc string IPC mode to use
  55. --isolation string Container isolation technology
  56. --kernel-memory bytes Kernel memory limit
  57. -l, --label list Set meta data on a container
  58. --label-file list Read in a line delimited file of labels
  59. --link list Add link to another container
  60. --link-local-ip list Container IPv4/IPv6 link-local addresses
  61. --log-driver string Logging driver for the container
  62. --log-opt list Log driver options
  63. --mac-address string Container MAC address (e.g., 92:d0:c6:0a:29:33)
  64. -m, --memory bytes Memory limit
  65. --memory-reservation bytes Memory soft limit
  66. --memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap
  67. --memory-swappiness int Tune container memory swappiness (0 to 100) (default -1)
  68. --mount mount Attach a filesystem mount to the container
  69. --name string Assign a name to the container
  70. --network network Connect a container to a network
  71. --network-alias list Add network-scoped alias for the container
  72. --no-healthcheck Disable any container-specified HEALTHCHECK
  73. --oom-kill-disable Disable OOM Killer
  74. --oom-score-adj int Tune host's OOM preferences (-1000 to 1000)
  75. --pid string PID namespace to use
  76. --pids-limit int Tune container pids limit (set -1 for unlimited)
  77. --platform string Set platform if server is multi-platform capable
  78. --privileged Give extended privileges to this container
  79. -p, --publish list Publish a container's port(s) to the host
  80. -P, --publish-all Publish all exposed ports to random ports ('端口映射')
  81. --read-only Mount the container's root filesystem as read only
  82. --restart string Restart policy to apply when a container exits (default "no")
  83. --rm Automatically remove the container when it exits
  84. --runtime string Runtime to use for this container
  85. --security-opt list Security Options
  86. --shm-size bytes Size of /dev/shm
  87. --sig-proxy Proxy received signals to the process (default true)
  88. --stop-signal string Signal to stop a container (default "SIGTERM")
  89. --stop-timeout int Timeout (in seconds) to stop a container
  90. --storage-opt list Storage driver options for the container
  91. --sysctl map Sysctl options (default map[])
  92. --tmpfs list Mount a tmpfs directory
  93. -t, --tty Allocate a pseudo-TTY
  94. --ulimit ulimit Ulimit options (default [])
  95. -u, --user string Username or UID (format: <name|uid>[:<group|gid>])
  96. --userns string User namespace to use
  97. --uts string UTS namespace to use
  98. -v, --volume list Bind mount a volume 定义目录绑定
  99. --volume-driver string Optional volume driver for the container
  100. --volumes-from list Mount volumes from the specified container(s)
  101. -w, --workdir string Working directory inside the container

例子

  • docker run -it -name container_name -v /to/path/local/:/to/path/container/ —gpus all image_name /bin/bash

docker exec

  1. Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
  2. Run a command in a running container
  3. Options:
  4. -d, --detach Detached mode: run command in the background
  5. --detach-keys string Override the key sequence for detaching a container
  6. -e, --env list Set environment variables
  7. -i, --interactive Keep STDIN open even if not attached
  8. --privileged Give extended privileges to the command
  9. -t, --tty Allocate a pseudo-TTY
  10. -u, --user string Username or UID (format: <name|uid>[:<group|gid>])
  11. -w, --workdir string Working directory inside the container

例子

  • docker exec -it container_name /bin/bash

docker commit

docker commit :从容器创建一个新的镜像。

  1. Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
  2. Create a new image from a container's changes
  3. Options:
  4. -a, --author string Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  5. -c, --change list Apply Dockerfile instruction to the created image
  6. -m, --message string Commit message
  7. -p, --pause Pause container during commit (default true)

例子

runoob@runoob:~$ docker commit -a “runoob.com” -m “my apache” a404c6c174a2 mymysql:v1