docker命令

docker

网络管理

  1. docker network create \
      --driver=bridge \
      --subnet=172.28.0.0/16 \
      --ip-range=172.28.5.0/24 \
      --gateway=172.28.5.254 \
      br0     -o com.docker.network.bridge.name=br0
    
  2. 修改ip addr网卡名称

    docker network list
    查看系统默认docker0(20d5d1508381)的底层信息

    [root@docker2 ~]# docker netwrok inspect 20d5d1508381

    ​ }
    ​ },
    ​ “Options”: {
    ​ “com.docker.network.bridge.default_bridge”: “true”,
    ​ “com.docker.network.bridge.enable_icc”: “true”,
    ​ “com.docker.network.bridge.enable_ip_masquerade”: “true”,
    ​ “com.docker.network.bridge.host_binding_ipv4”: “0.0.0.0”,
    ​ “com.docker.network.bridge.name": "docker0”, #注意这个命令行
    ​ “com.docker.network.driver.mtu”: “1500”
    ​ },
    ​ “Labels”: {}
    }
    ]

  3.  docker network inspect [OPTIONS] NETWORK [NETWORK...]
    
  4.  docker network prune [OPTIONS]
     Remove all unused networks. Unused networks are those which are not referenced by any containers.
    
  5.  docker network rm 3695c422697f|my-network
    

docker命令

  1. docker search

  2. docker pull

  3. docker commit

    docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
    Create a new image from a container’s changes
    
  4. docker export

    docker export [OPTIONS] CONTAINER
    Export a container’s filesystem as a tar archive
    
  5. docker import

    docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
    Import the contents from a tarball to create a filesystem image
    docker import https://example.com/exampleimage.tgz
    
  6. docker load

     docker load [OPTIONS]
    docker image ls
     docker load < busybox.tar.gz
     docker images
     docker load --input fedora.tar
     docker images
    
  7. docker save

     docker save busybox > busybox.tar
     ls -sh busybox.tar
     docker save --output busybox.tar busybox
    
  8. docker info

  9. docker inspect

    Get an instance’s IP address

    For the most part, you can pick out any field from the JSON in a fairly straightforward manner.

     docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID
    

    Get an instance’s MAC address

     docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' $INSTANCE_ID
    

    Get an instance’s log path

     docker inspect --format='{{.LogPath}}' $INSTANCE_ID
    

    Get an instance’s image name

     docker inspect --format='{{.Config.Image}}' $INSTANCE_ID
    

    List all port bindings

    You can loop over arrays and maps in the results to produce simple text output:

     docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
    

    Find a specific port mapping

    The .Field syntax doesn’t work when the field name begins with a number, but the template language’s index function does. The .NetworkSettings.Ports section contains a map of the internal port mappings to a list of external address/port objects. To grab just the numeric public port, you use index to find the specific port map, and then index 0 contains the first object inside of that. Then we ask for the HostPort field to get the public address.

     docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
    

    Get a subsection in JSON format

    If you request a field which is itself a structure containing other fields, by default you get a Go-style dump of the inner values. Docker adds a template function, json, which can be applied to get results in JSON format.

     docker inspect --format='{{json .Config}}' $INSTANCE_ID
    
  10. docker kill my_container
    Send a KILL signal to a container
    
  11. docker rename

    docker rename CONTAINER NEW_NAME
    
  12. docker restart

     docker restart [OPTIONS] CONTAINER [CONTAINER...]
    
  13. docker rm

    docker rm [OPTIONS] CONTAINER [CONTAINER...]
    
  14. docker rmi

    docker rmi [OPTIONS] IMAGE [IMAGE...]
    
  15. docker run

    docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
    docker run --name test -it debian
    docker run -t -i --rm ubuntu bash
    docker run -t -i --privileged ubuntu bash
    docker  run -w /path/to/dir/ -i -t  ubuntu pwd
    docker run -v /doesnt/exist:/foo -w /foo -i -t ubuntu bash
    docker run --read-only -v /icanwrite busybox touch /icanwrite/here
    docker run -t -i -v /var/run/docker.sock:/var/run/docker.sock -v /path/to/static-docker-binary:/usr/bin/docker busybox sh
    docker run -t -i --mount type=bind,src=/data,dst=/data busybox sh
    docker run --read-only --mount type=volume,target=/icanwrite busybox touch /icanwrite/here
    docker run -p 127.0.0.1:80:8080/tcp ubuntu bash
    docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash
    docker run -itd --network=my-net --ip=10.10.9.75 busybox
    docker run --restart=always redis
           noon-failure[:max-retries]unless-stopped always
    docker run --sysctl net.ipv4.ip_forward=1 someimage
    docker start [OPTIONS] CONTAINER [CONTAINER...]
    docker stop [OPTIONS] CONTAINER [CONTAINER...]
    

docker image 命令

  1. docker image ls
  2. rm
  3. pull

docker container命令

  1. docker container ls -a
  2. stop
  3. rm
  4. start
  5. restart

容器配置文件

  1. /var/lib/docker/containers

注意:先关闭docker,再修改配置文件
systemctl stop docker

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值