Docker 容器镜像删除

1.停止所有的container,这样才能够删除其中的images:

docker stop $(docker ps -a -q)

如果想要删除所有container的话再加一个指令:

docker rm $(docker ps -a -q)

2.查看当前有些什么images

docker images

3.删除images,通过image的id来指定删除谁

docker rmi <image id>

想要删除untagged images,也就是那些id为<None>的image的话可以用

docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

要删除全部image的话

docker rmi $(docker images -q)

 

 

  1. Try something more ambitious, and run an Ubuntu container with this command.

    PS C:\Users\jdoe> docker run -it ubuntu bash
    

    This will download the ubuntu container image and start it. Here is the output of running this command in a powershell.

    PS C:\Users\jdoe> docker run -it ubuntu bash
    
    Unable to find image 'ubuntu:latest' locally
    latest: Pulling from library/ubuntu
    5a132a7e7af1: Pull complete
    fd2731e4c50c: Pull complete
    28a2f68d1120: Pull complete
    a3ed95caeb02: Pull complete
    Digest: sha256:4e85ebe01d056b43955250bbac22bdb8734271122e3c78d21e55ee235fc6802d
    Status: Downloaded newer image for ubuntu:latest
    

    Type exit to stop the container and close the powershell.

  2. Start a Dockerized webserver with this command:

    PS C:\Users\jdoe> docker run -d -p 80:80 --name webserver nginx
    

    This will download the nginx container image and start it. Here is the output of running this command in a powershell.

    PS C:\Users\jdoe> docker run -d -p 80:80 --name webserver nginx
    
    Unable to find image 'nginx:latest' locally
    latest: Pulling from library/nginx
    
    fdd5d7827f33: Pull complete
    a3ed95caeb02: Pull complete
    716f7a5f3082: Pull complete
    7b10f03a0309: Pull complete
    Digest: sha256:f6a001272d5d324c4c9f3f183e1b69e9e0ff12debeb7a092730d638c33e0de3e
    Status: Downloaded newer image for nginx:latest
    dfe13c68b3b86f01951af617df02be4897184cbf7a8b4d5caf1c3c5bd3fc267f
    

Point your web browser at http://localhost to display the start page.

(Since you specified the default HTTP port, it isn’t necessary to append :80 at the end of the URL.)Run nginx edge>

  1. Run docker ps while your webserver is running to see details on the container.

    PS C:\Users\jdoe> docker ps
    
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS
    NAMES
    dfe13c68b3b8        nginx               "nginx -g 'daemon off"   3 days ago          Up 45 seconds       0.0.0.0:80->80/tcp, 443/tc
    p   webserver
    
  2. Stop or remove containers and images.

    The nginx webserver will continue to run in the container on that port until you stop and/or remove the container. If you want to stop the webserver, type: docker stop webserver and start it again with docker start webserver.

    To stop and remove the running container with a single command, type: docker rm -f webserver. This will remove the container, but not the nginx image. You can list local images with docker images. You might want to keep some images around so that you don’t have to pull them again from Docker Hub. To remove an image you no longer need, use docker rmifollowed by an image ID or image name. For example, docker rmi nginx

posted @ 2017-06-15 11:40  Javi  阅读(443)  评论(0编辑  收藏  举报