docker-Error No such container,附docker常用命令

转载地址:https://blog.csdn.net/ithaibiantingsong/article/details/81353168
——————————————————————————————————
最近打算删除掉docker镜像但是发现有几个镜像就是删除不了,加了-f强制删除也不行,一直报Error: No such container的错误,最后终于找到了办法直接删除文件,步骤如下:

切换到root用户然后:

service docker stop

rm -rf /var/lib/docker
start docker.service
到这里就会发现镜像已经删除干净。

附docker常用命令:

重启docker服务sudo service docker restart

关闭docker服务dockerservice docker stop

开启docker服务dockerservice docker start

查看当前运行的容器:docker ps

查询存在的容器:docker ps -a

删除容器:docker -rmCONTAINERID

强制删除容器:docker -rm -f CONTAINERID

不能够删除一个正在运行的容器,会报错。需要先停止容器。

查看镜像:docker images

删除镜像:docker -rmiIMAGEID

强制删除镜像:docker -rmi -f IMAGEID

利用镜像创建容器:docker run --name centos -itd centos:latest

注:-i表示让容器的标准输入打开,-t表示分配一个伪终端,-d表示后台启动,要把-i -t -d 放到镜像名字前面,–name指定容器名。

docker run -d -t --name hello-world -p 8762:8762 -v /home/app/hello.jar:/home/app/hello.jar java8 java -jar /home/app/hello.jar --spring.profiles.active=dev
-d 表示在后台启动
-p 8762:8762 表示将容器的端口 映射成宿主主机的端口,否则8762端口访问不到
-v /home/app/hello.jar:/home/app/hello.jar 表示将宿主主机的jar文件,映射到容器中(分号前为宿主主机的路径,分号后为容器中的路径)
--name hello-world表示为该容器取一个全局唯一的名称,这里我取的名称为hello-world
java8 表示镜像文件的名称(为Java镜像重命名后的名称)
java -jar /home/app/hello.jar 表示运行jar包,注意:这里的jar包为容器中的位置,是通过前面的-v属性映射的
--spring.profiles.active=dev 表示spring boot项目配置文件选用dev的配置

如果使用systemctl启动服务需要用下面的方式以超级权限启动,否则会报Failed to get D-Bus connection: Operation not permitted错误:

docker run --name centos-itd --privileged=true centos:latest /usr/sbin/init

进入后台运行的容器:docker exec -it containname/bin/bash

启动容器:docker start containername

停止容器:docker stopcontainername

停止所有的container,这样才能够删除其中的images: docker stop $(docker ps -a -q)

如果想要删除所有container的话再加一个指令: docker rm $(docker ps -a -q)

注:-a标志列出所有容器,-q标志只列出容器的ID,然后传递给rm命令

删除全部image的: docker rmi $(docker images -q)

重命名一个容器:docker rename old_name new_name

要获取所有容器名称及其IP地址:

docker inspect -f ‘{{.Name}} - {{.NetworkSettings.IPAddress }}’ $(docker ps -aq)

进入容器内部后可以使用下面命令获取目前容器的ip:

cat /etc/hosts

在docker容器和宿主机之间复制文件:

切换为root用户然后:

从主机复制到容器?docker cp host_path containerID:container_path

从容器复制到主机?docker cp containerID:container_path host_path

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Run Docker on AWS and build real-world, secure, and scalable container platforms on cloud Key Features Configure Docker for the ECS environment Integrate Docker with different AWS tools Implement container networking and deployment at scale Book Description Over the last few years, Docker has been the gold standard for building and distributing container applications. Amazon Web Services (AWS) is a leader in public cloud computing, and was the first to offer a managed container platform in the form of the Elastic Container Service (ECS). Docker on Amazon Web Services starts with the basics of containers, Docker, and AWS, before teaching you how to install Docker on your local machine and establish access to your AWS account. You'll then dig deeper into the ECS, a native container management platform provided by AWS that simplifies management and operation of your Docker clusters and applications for no additional cost. Once you have got to grips with the basics, you'll solve key operational challenges, including secrets management and auto-scaling your infrastructure and applications. You'll explore alternative strategies for deploying and running your Docker applications on AWS, including Fargate and ECS Service Discovery, Elastic Beanstalk, Docker Swarm and Elastic Kubernetes Service (EKS). In addition to this, there will be a strong focus on adopting an Infrastructure as Code (IaC) approach using AWS CloudFormation. By the end of this book, you'll not only understand how to run Docker on AWS, but also be able to build real-world, secure, and scalable container platforms in the cloud. What you will learn Build, deploy, and operate Docker applications using AWS Solve key operational challenges, such as secrets management Exploit the powerful capabilities and tight integration of other AWS services Design and operate Docker applications running on ECS Deploy Docker applications quickly, consistently, and reliably using IaC Manage and operate Docker clusters and applications for no additional cost Who this book is for Docker on Amazon Web Services is for you if you want to build, deploy, and operate applications using the power of containers, Docker, and Amazon Web Services. Basic understanding of containers and Amazon Web Services or any other cloud provider will be helpful, although no previous experience of working with these is required. Table of Contents Chapter 1 Container and Docker Fundamentals Chapter 2 Building Applications Using Docker Chapter 3 Getting Started with AWS Chapter 4 Introduction to ECS Chapter 5 Publishing Docker Images using ECR Chapter 6 Building Custom ECS Container Instances Chapter 7 Creating ECS Clusters Chapter 8 Deploying Applications using ECS Chapter 9 Managing Secrets Chapter 10 Isolating Network Access Chapter 11 Managing ECS Infrastucture Lifecycle Chapter 12 ECS Auto Scaling Chapter 13 Continuously Delivering ECS Applications Chapter 14 Fargate and ECS Service Discovery Chapter 15 Elastic Beanstalk Chapter 16 Docker Swarm in AWS Chapter 17 Elastic Kubernetes Service Chapter 18 Assessments

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值