docker常用命令

 docker所有命令集合

  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  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
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  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
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  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
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  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
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

 查看某个命令的使用细节

docker xxx --help

 从官方镜像库拉取镜像

docker pull python:3.7

显示本地镜像

docker image list

使用特定镜像启动一个容器,并进入命令行,注意,如果不带/bin/bash会直接启动python,在终端shell下直接输入exit可以退出终端。

docker run -it python:3.7 /bin/bash --name="your name"

注意,不加name选项系统会自动分配一个奇怪的名字给你,类似随机的游戏ID名字, 比如心如磐石的张三

docker run -itd  python:3.7 /bin/bash

 查看运行中的容器

docker ps -a

这里注意,当你运行一个容器后退出,这个容器虽然停止了,但是容器的实体还在。

启动一个已经穿见过的容器,XXX是容器的ID。如果需要shell交互,加 -i

docker start xxxx

对应的,停止一个容器,依然需要知道ID。

docker stop xxx

运行一个exit后不停止的容器

docker exec -it 243c32535da7 /bin/bash

当你基于某个镜像的容器进行了自己的环境配置后,想要导出你的容器,使用一下步骤

导出一个容器

 docker export 861 -o p37numpy.tar

导入一个容器

docker import .\p37numpy.tar py37:numpy

如果需要将镜像直接进行保存和载入,可以使用load和save

docker save 24f00 -o p37.tar
docker load -i .\p37.tar

注意,如果使用了load,那么会替换一样的镜像。

如果是你改了某镜像的容器,并想把这些更改加入到镜像中,使用命令 

 95是ID, py37numpy是name,928是tag

docker commit -m "add numpy" -a "Yan" 95 py37numpy:928

commit以后就会出现一个新的镜像,可以push这个镜像,这里注意,xxy是你自己的仓库名字

docker push xxy/py37numpy

 查看一个镜像的详细信息

docker inspect xxx

查看docker占用内存情况

docker system df

清理空间,慎用!

docker system prune

拷贝主机文件到容器中

docker cp yourfile containerID:targetDir

 Linux下docker使用主机显示和网络,也就是可视化图形显示

docker run --net=host --env="DISPLAY"

这里特别要注意一点,在arm上构建的docker镜像可能无法应用于普通的X86电脑。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Gaosiy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值