Home  >  Q&A  >  body text

docker build -t .失败后,遇到奇怪问题

Dockerfile

FROM ubuntu
RUN apt-get update && apt-get install -y mysql-server php5 php5-xdebug

创建失败,因为找不到几个包
docker build -t docker_image1 .

E: Package 'php5' has no installation candidate
E: Unable to locate package php5-xdebug

该操作生成了一个没名字的image
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
<none> <none> 77d786364eba 25 minutes ago 122 MB

无法删除,因为某个容器在用它
docker rmi 77d7 -f
Error response from daemon: Conflict, cannot delete 77d786364eba because the container c4283c57025d is using it, use -f to force
Error response from daemon: No such image: -f
FATA[0000] Error: failed to remove one or more images

docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c4283c57025d 77d786364ebafecb599657f5d96053e5fb6829f22129e5002b3e3eddb672b7ae:latest "/bin/sh -c 'apt-get 28 minutes ago Exited (100) 4 minutes ago reverent_goodall

docker start c428
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c4283c57025d 77d786364ebafecb599657f5d96053e5fb6829f22129e5002b3e3eddb672b7ae:latest "/bin/sh -c 'apt-get 28 minutes ago Up 2 seconds reverent_goodall

启动容器后,为何连不上?
试过很多次了,都不行。 是否只能删除容器和镜像,不能基于c428镜像做修改么?

刚才明明显示已经启动的,为何连不上呢?
docker attach c428
FATA[0000] You cannot attach to a stopped container, start it first

此时docker ps发现容器停止了。 启动容器成功,连接连不上,同时容器自动停止,这是什么情况?

有人遇到过?

黄舟黄舟2707 days ago827

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-25 09:05:00

    When you use docker build to build an image, you actually create a container based on the basic image, and run the first instruction in this container. After that, it will be saved as an image and the container will be deleted. Then create a container based on this new image, execute the second command, save it as an image, delete the container, and delete the previous image (only the image information is deleted, the image layer is not deleted). If repeated, until the last instruction is completed, the target image will be obtained.

    So if an accident occurs during the build process, there will be a container that exits unexpectedly, and the upper-layer image it depends on. In fact, these are all useless things, we can delete them directly. Because the container depends on the image, delete the container first before deleting the image.

    reply
    0
  • Cancelreply