This script automatically deploys a Docker Swarm cluster on our infra.
Once this is done, you can create docker services. In other words you can take your docker-compose.yml and "transform" it into a persistent service.
ssh deploy@10.33.0.11
# Get information about services...
sudo docker stack ls
sudo docker service ls # See all the services running on the cluster...
git clone https://my_awesome_service
cd my_awesome_service
sudo docker-compose build
sudo docker-compose push
sudo docker stack deploy NAME_OF_YOUR_SERVICE --compose-file docker-compose.yml
- Build the service
- Push the service to our registry
- Deploy the service
In order for the containers to be available to all of the VM running Docker, you must specify a registry server of the cluster in your docker-swarm.yml.
The registry will store the built version of your containers.
First, if you build some custom containers in your dockerfile, for instance:
version: '3'
services:
api:
build: ./api
environment:
MY_ENV_VAR: 5000
[...]
Add a "image:" directive for each build:.
version: '3'
services:
api:
build: ./api
image: localhost:5000/rootme_api_python
environment:
MY_ENV_VAR: 5000
[...]
Then you will build your service.
SSH on docker1:
ssh deploy@10.33.0.11
# Transfer your project on the VM... (you can use git, wget, scp...)
git clone https://my_awesome_service
cd my_awesome_service
sudo docker-compose build
sudo docker-compose push
sudo docker stack deploy NAME_OF_YOUR_SERVICE --compose-file docker-compose.yml
sudo docker stack ls
sudo docker service ls # See all the services running on the cluster...