在使用 docker-compose 建立 Docker 时,会去使用 Dockerfile 去建立自己想要的环境,但建立完成后 docker 会自行命名这个 Dockerfile 的 images
version: '3'
services:
cronjob:
container_name: dev_cronjob
build: cron.Dockerfile
volumes:
- /web/:/var/web
restart: always
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dev_cronjob latest 91e20032b3ff 23 minutes ago 502MB
若想要有自己指定的 images 名称让我们方便管理的话,可以在 docker-compose.yml
档案中加入 images
去指定建立完成后的映像档名称
images: <images-name>:<images-version>
version: '3'
services:
cronjob:
container_name: dev_cronjob
build: cron.Dockerfile
images: my_cron_image:v1.0
volumes:
- /web/:/var/web
restart: always
这样使用 docker-compose build
后,就可以在 docker images
看到这个映像档有他自己的命名了
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my_cron_image v1.0 91e20032b3ff 23 minutes ago 502MB