I have a Dockerfile
as the following:
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
I have built the above Dockerfile
as image: docker-whale
I want to write a docker-compose.yml
for the above image. My understanding is that you can run multiple containers with docker-compose.
So if i want to run 5 images of docker-whale
, how does docker-compose.yml
looks like?
You could put this docker-compose.yaml
next to your Dockerfile
:
version: '2'
services:
docker-whale:
image: docker-whale
build: .
And then execute the following commands:
# 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 <ctrl-c> to stop viewing
docker-compose logs --follow
# take down all containers
docker-compose down
version:"3"
services: docker-whale:
image:docker-whale
deploy:
replicas:5
resources:
limits:
cpus:"0.1"
memory: 50M
restart_policy:
condition: on-failure
ports: "80:80"
...
Above is how your docker-compose.yml should look like. This docker-compose.yml tells Dockers to do the following:
Ref: https://docs.docker.com/get-started/part3/#docker-composeyml
Hope it helps
I assume you want to run 5 containers of docker-whale and not 5 images .
In your case compose.yml will not have information about number of containers. You need to use scale command
docker-compose scale <service-name>=5
docker-compose.yml
docker-whale:
image: docker-whale
Then inside same folder run:
docker-compose up -d
docker-compose scale docker-whale=5
This assumes your application is scale-aware, but you still can write 5 entries in docker-compose.yml, this is screwdriver but sometimes useful:
docker-whale-1:
image: docker-whale
docker-whale-2:
image: docker-whale
docker-whale-3:
image: docker-whale
docker-whale-4:
image: docker-whale
docker-whale-5:
image: docker-whale
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.