我有一个Dockerfile如下:
FROM docker/whalesay:latest
RUN apt-get update && apt-get install -y fortunes
CMD while true; do /usr/games/fortune -a | cowsay; sleep 2; done
我已将上面的Dockerfile构建为image:docker-whale
我想为上面的图片写一个docker-compose.yml.我的理解是你可以使用docker-compose运行多个容器.
所以,如果我想运行5个docker-whale图像,docker-compose.yml是怎么样的?
最佳答案
你可以把这个docker-compose.yaml放在你的Dockerfile旁边:
version: '2'
services:
docker-whale:
image: docker-whale
build: .
然后执行以下命令:
# build docker image
docker-compose build
# bring up one docker container
docker-compose up -d
# scale up to three containers
docker-compose scale docker-whale=3
# overview about these containers
docker-compose ps
# view combined logs of all containers
# use