3、ubuntu系统docker常用命令

1、自助查看docker命令

1.1、查看所有命令

docker 客户端非常简单,可以直接输入 docker 命令来查看到 Docker 客户端的所有命令选项。

angqiang@wangqiang:~$ docker

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Common Commands:
  run         Create and run a new container from an image
  exec        Execute a command in a running container
  ps          List containers
  build       Build an image from a Dockerfile
  pull        Download an image from a registry
  push        Upload an image to a registry
  images      List images
  login       Log in to a registry
  logout      Log out from a registry
  search      Search Docker Hub for images
  version     Show the Docker version information
  info        Display system-wide information

Management Commands:
  builder     Manage builds
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  plugin      Manage plugins
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Swarm Commands:
  swarm       Manage Swarm

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  import      Import the contents from a tarball to create a filesystem image
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  wait        Block until one or more containers stop, then print their exit codes

Global Options:
      --config string      Location of client config files (default "/home/wangqiang/.docker")
  -c, --context string     Name of the context to use to connect to the daemon (overrides
                           DOCKER_HOST env var and default context set with "docker
                           context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket to connect to
  -l, --log-level string   Set the logging level ("debug", "info", "warn", "error",
                           "fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default
                           "/home/wangqiang/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default
                           "/home/wangqiang/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/home/wangqiang/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Run 'docker COMMAND --help' for more information on a command.

For more help on how to use Docker, head to https://docs.docker.com/go/guides/

1.2、查看命令使用说明

可以通过命令 docker command --help 更深入的了解指定的 Docker 命令使用方法。

wangqiang@wangqiang:~$ docker ps --help

Usage:  docker ps [OPTIONS]

List containers

Aliases:
  docker container ls, docker container list, docker container ps, docker ps

Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Format output using a custom template:
                        'table':            Print output in table format with column
                        headers (default)
                        'table TEMPLATE':   Print output in table format using the given
                        Go template
                        'json':             Print in JSON format
                        'TEMPLATE':         Print output using the given Go template.
                        Refer to https://docs.docker.com/go/formatting/ for more
                        information about formatting output with templates
  -n, --last int        Show n last created containers (includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display container IDs
  -s, --size            Display total file sizes

2、docker命令大全

2.1、容器生命周期管理

docker create

docker create [OPTIONS] IMAGE [COMMAND] [ARG...]:创建一个容器,但不启动它。

docker run

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]:创建并启动一个容器。

docker start

docker start [OPTIONS] CONTAINER [CONTAINER...]:启动一个或多个已停止的容器。

docker stop

docker stop [OPTIONS] CONTAINER [CONTAINER...]:停止一个或多个正在运行的容器。

docker restart

docker restart [OPTIONS] CONTAINER [CONTAINER...]:重启一个或多个容器。

docker rm

docker rm [OPTIONS] CONTAINER [CONTAINER...]:删除一个或多个容器。

docker container prune

docker container prune:删除所有已停止的容器。

docker pause CONTAINER

docker pause CONTAINER:暂停容器的所有进程。

docker unpause CONTAINER

docker unpause CONTAINER:恢复容器的所有进程。

2.2、容器操作

docker ps

docker ps [OPTIONS]:列出容器。

docker ps -a

docker ps -a:列出所有容器(包括已停止的)。

docker logs

docker logs [OPTIONS] CONTAINER:获取容器的日志。

docker exec

docker exec [OPTIONS] CONTAINER COMMAND [ARG...]:在运行的容器中执行命令。

docker attach

docker attach [OPTIONS] CONTAINER:连接到正在运行的容器。

docker export

docker export [OPTIONS] CONTAINER:将容器导出为 tar 归档文件。

docker import

docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]:从 tar 归档文件或 URL 导入容器。

2.3、容器的 root 文件系统(rootfs)命令

docker diff CONTAINER

docker diff CONTAINER:检查容器文件系统中的更改。

docker cp

docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH:从容器复制文件到主机。

docker cp

docker cp [OPTIONS] SRC_PATH CONTAINER:DEST_PATH:从主机复制文件到容器。

2.4、镜像仓库

docker login

docker login [OPTIONS] [SERVER]:登录到 Docker 镜像仓库。

docker logout

docker logout [SERVER]:登出 Docker 镜像仓库。

docker search

docker search [OPTIONS] TERM:搜索 Docker Hub 上的镜像。

2.5、本地镜像管理

docker images

docker images [OPTIONS] [REPOSITORY[:TAG]]:列出本地镜像。

docker rmi

docker rmi [OPTIONS] IMAGE [IMAGE...]:删除一个或多个镜像。

docker image prune

docker image prune:删除所有未使用的镜像。

docker build

docker build [OPTIONS] PATH | URL | -:从 Dockerfile 构建镜像。

docker pull

docker pull [OPTIONS] NAME[:TAG|@DIGEST]:从仓库拉取镜像。

docker push

docker push [OPTIONS] NAME[:TAG]:将镜像推送到仓库。

docker history

docker history [OPTIONS] IMAGE:显示镜像的历史。

2.6、info|version

docker info

docker info [OPTIONS]:显示 Docker 系统信息。

docker version

docker version [OPTIONS]:显示 Docker 版本信息。

2.7、Docker Compose

通常通过包管理器(如 apt-get)安装Docker Compose

docker-compose up

docker-compose up:启动服务。

docker-compose down

docker-compose down:停止并移除服务。

docker-compose build

docker-compose build:构建服务。

docker-compose ps

docker-compose ps:列出服务状态。

docker-compose logs

docker-compose logs:查看服务日志。

2.8、网络命令

docker network ls

docker network ls:列出所有网络。

docker network create

docker network create [OPTIONS] NETWORK:创建一个网络。

docker network rm

docker network rm NETWORK [NETWORK...]:删除一个或多个网络。

docker network connect

docker network connect [OPTIONS] NETWORK CONTAINER:将容器连接到网络。

docker network disconnect

docker network disconnect [OPTIONS] NETWORK CONTAINER:将容器从网络断开。

2.9、卷命令

docker volume ls

docker volume ls:列出所有卷。

docker volume create

docker volume create [OPTIONS] [VOLUME]:创建一个卷。

docker volume rm

docker volume rm [OPTIONS] VOLUME [VOLUME...]:删除一个或多个卷。

docker volume prune

docker volume prune:删除所有未使用的卷。

2.10、补充说明

docker system df

docker system df:显示 Docker 磁盘使用情况。

docker system prune

docker system prune:清理未使用的对象(容器、镜像、网络等)。

你可能感兴趣的:(Ubuntu系统,Docker,docker)