Vous êtes sur la page 1sur 3

Domain 1: Orchestration (25% of exam)

#create docker swarm manager

docker swarm init --advertise-addr <MANAGER-IP>

#check the state of swarm

$docker info

Swarm: active

#check the info about the nodes

$ docker node ls

#Add the nodes to swarm

docker swarm join --token SWMTKN-1-


4zsebmercotxmjciduk1fmsrre3axw10dce9z12hk7audxem4w-cnqv9znxl119leuj3xzgdnq93
192.168.0.8:2377

#Configure container rootfs to 5G

docker run -it --storage-opt size=5G fedora /bin/bash

#publish the port externally

$ docker run -p 127.0.0.1:80:8080 ubuntu bash

#Publish the port to container interface.

docker run --expose 80 ubuntu bash

#Connect container to my-net

docker run -itd --network=my-net busybox

Note: Note: Service discovery is unavailable on the default bridge network.


Containers can communicate via their IP addresses by default.
To communicate by name, they must be linked.

#Connect a network to a container seperately

docker network connect <networkid> <containerid>

#Mount volumes from a running container to a new container

docker run --volumes-from <containerid> --volumes-from <containerid>:ro -i -t


ubuntu pwd

#Docker restart policy


no(default),on-failure[:max-retries],always

$ docker run --restart=always redis

#Service details in json format, run the same command without the --pretty flag.

docker service inspect --pretty <SERVICE-ID>

#Find which nodes are running the service

docker service ps <SERVICE-ID>

#Scale-in/down a service in swarm cluster

docker service update --replicas <1-10> <SERVICE-ID>


or
docker service scale SERVICE=NUMBER

#Publish a service port using Routing Mesh(Ingress)

docker service create --name <> --publish published=8080,target=80, --replicas=<>


ngnix

#PUBLISH A SERVICE’S PORTS DIRECTLY ON THE SWARM NODE(PublishMode": "host")

$ docker service create --mode global|host --publish


mode=host,target=80,published=8080 --name=nginx nginx:latest

#Connect an existing service to an overlay network using the --network-add

$docker service update --network-add my-network my-web

#REPLICATED OR GLOBAL SERVICES


$ docker service create --name my_web --replicas 3 nginx (By default replicated)
$docker service create --name myservice --mode global alpine top

#PLACEMENT CONSTRAINTS

$ docker service create --name my-nginx --replicas 5 --constraint region==east


nginx

#Docker service update

docker service create --replicas 10 --name my_web --update-delay 10s --update-


parallelism 2 --update-failure-action continue alpine

#Rollback service update

$ docker service update --rollback --update-delay 0s my_web


#Disconnect a running service from a network, use the --network-rm flag.

docker service update --network-rm my-network my-web


#Deploy a new stack or update an existing stack(dab & yml)
docker stack deploy --compose-file docker-compose.yml vossibility

#Create service using Template


docker service create --name hosttempl --hostname="{{.Node.Hostname}}-{{.Node.ID}}-
{{.Service.Name}}" busybox top

If your configuration is split between multiple Compose files, e.g. a


base configuration and environment-specific overrides, you can combine these
by passing them to docker-compose config with the -f option and redirecting the
merged output into a new file.

$ docker-compose -f docker-compose.yml -f docker-compose.prod.yml config > docker-


stack.yml
$ docker stack deploy --compose-file docker-stack.yml vossibility

docker stack deploy --bundle-file vossibility-stack.dab vossibility

#Docker bind volumes

docker service create --mount type=bind,src=/docker,dst=/docker --name myservice


ngnix

Vous aimerez peut-être aussi