version: "3" services: web: # replace username/repo:tag with your name and image details image: username/repo:tag deploy: replicas: 5 resources: limits: cpus: "0.1" memory: 50M restart_policy: condition: on-failure ports: - "80:80" networks: - webnet networks: webnet:
- web define the name of the service as web
- image: defines the image to pull
- replicas defines the number of instances to run
- limits limits each replica to use, at most, 10% of the CPU (across all cores), and 50MB of RAM.
- restart_policy defines that a replica must restart on failure
- ports map the port 80 on the host to web’s port 80. See Docker - Port
- webnet defines a load-balanced network that shares the port 80 (Internally, the containers themselves publish to web’s port 80 at an ephemeral port.). The default settings is a load-balanced overlay network.
Run the specified Compose file. See Docker - App
docker swarm init docker stack deploy -c <composefile> <appname>
version: '2' services: serviceName: ports: - "8080:8080" - "80:80" - ...
version: '2' services: serviceName: networks: - netWorkName networks: networkName: driver: bridge