如何使用docker-compose指定镜像名称

4

这是我的docker-compose文件

我使用docker-compose build命令构建了镜像。

如何构建命名的镜像?因为我有太多没有命名的镜像。

DOCKERFILE

    FROM rails:onbuild
    # RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
    RUN apt-get update && apt-get -y upgrade
    RUN apt-get -y -qq --force-yes install \
            build-essential \
            tree \
            ruby-dev \
            vim \
            vim-scripts \
            git \
            git-flow\
            curl \
            zsh \
            sudo


# Install Zsh
################## BEGIN INSTALLATION ######################
RUN git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh \
      && cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc \
      && chsh -s /bin/zsh

docker-compose.yml

db:
  image: postgres
  ports:
    - "5432"
web:
  build: .
  command: bundle exec rails s -p 3001 -b '0.0.0.0'
  volumes:
    - .:/associated-press
  ports:
    - "3001:3001"
  links:
    - db

太多无名图片

associated_press git:(master) ✗ docker images                                                                                                                 (master⚡)
REPOSITORY               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>                   <none>              80c216ddb2a7        About an hour ago   1.093 GB
<none>                   <none>              115a747757ec        About an hour ago   1.065 GB
associatedpress_web      latest              cf136ac96689        About an hour ago   1.185 GB
<none>                   <none>              c3e538c87495        17 hours ago        1.185 GB
<none>                   <none>              c41d47cc6647        17 hours ago        1.185 GB
<none>                   <none>              cd57f0d2165f        17 hours ago        1.185 GB
<none>                   <none>              64544f8cb188        17 hours ago        1.185 GB
<none>                   <none>              afd369c991d1        17 hours ago        1.185 GB
<none>                   <none>              54113a645b47        19 hours ago        1.184 GB
<none>                   <none>              d6986f926c4a        19 hours ago        1.184 GB
<none>                   <none>              a22979b350af        19 hours ago        1.184 GB
<none>                   <none>              5efecb684ecd        19 hours ago        1.064 GB
<none>                   <none>              fca65cdaecfc        19 hours ago        1.184 GB
<none>                   <none>              bf6ff095eedb        19 hours ago        1.064 GB
<none>                   <none>              0697417f2fd1        19 hours ago        1.064 GB
<none>                   <none>              9ed0d5b6fc70        19 hours ago        1.064 GB
<none>                   <none>              f883183e0870        20 hours ago        1.161 GB
<none>                   <none>              caa221a5f56e        20 hours ago        1.161 GB
<none>                   <none>              88e6c706176f        20 hours ago        1.064 GB
<none>                   <none>              3b48ab1152f4        20 hours ago        1.064 GB
1个回答

3

我不知道如何设置自定义图片名称,Compose总是将图片标记为project_service:latest。我们使用的一种模式类似于这样的启动脚本:

#!/bin/sh
docker-compose kill
docker-compose rm --force -v
docker rmi project_service:latest    # prevents buildup of untagged images
docker-compose build
docker-compose up -d

如果你不想使用启动脚本,另一个解决方案是经常运行以下命令:
docker rmi $(docker images -q -f dangling=true)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接