- Download Vagrant and Virtualbox and install them.
- If you are running Windows, install Git Bash
- Open ports 2375, 4000 and 8500 or disable firewall
- Change the hostname in the Vagrantfile, line 4, check that your hostname is unique
Start the vagrant machine, which is going to download and configure everything. In the folder where your Vagrantfile is:
vagrant up
- Create a consul server (Only on the manager)
docker run -d -p 8500:8500 --name=consul progrium/consul -server -bootstrap
- Start the swarm manager (Only on the manager)
docker run -d -p 4000:4000 swarm manage -H :4000 --advertise <manager-ip>:4000 consul://<manager-ip>:8500
- Connect to the vagrant machine through SSH
vagrant ssh
- Start the swarm clients
docker run -d swarm join --advertise=<your-vm-ip>:2375 consul://<manager-ip>:8500
- Start one miner
docker -H :4000 run -d kourkis/miner
- To remove all of the miners
docker -H :4000 ps -q | xargs docker -H :40bbbb00 rm -f
- To create several miners in a single command
for i in {1..5}; do docker -H :4000 run -d kourkis/miner; done
Most Docker API endpoints are implemented by Swarm, meaning that tools built on top of it will work out of the box, including the Docker CLI. Visit the API documentation to get more details.
There is no need to do it during this meetup, as this is taken care of in the Vagrantfile. This is simply for your information.
- Without security: For the purpose of the Meetup we open the socket to everyone and don't use TLS for securing the Remote API Access.
Add
-H tcp://<ip>:<port>
to theDOCKER_OPTS
in/etc/default/docker
.
Reference - With security: For securing it see this documentation.
The following GET commands can be run from your web browser.
http://<manager-ip>:<port>/containers/json
<manager-ip>
- The Docker Swarm manager IP. Docker Swarm Manager IP to access containers in the cluster level.<port>
- The Docker Swarm Manager listening port. - (Alternative) From the command line, we execute the following command
curl -X GET http://<manager-ip>:<port>/containers/json
http://<manager-ip>:<port>/containers/<container-id or container-name>/json
<manager-ip>
- The Docker Swarm manager IP. Docker Swarm Manager IP to access containers in the cluster level.<port>
- The Docker Swarm Manager listening port. - (Alternative) From the command line, we execute the following command
curl -X GET http://<manager-ip>:<port>/containers/<container-id or container-name>/json
http://<docker-node-ip>:<open-port>/containers/<container-id or container-name>/logs?stderr=1&stdout=1&
- Include the
logs
keyword after the container id/name stdout
–1/True/true
or0/False/false
, showstdout
log. Default false.stderr
–1/True/true
or0/False/false
, showstderr
log. Default false. - (Alternative) From the command line, we execute the following command
curl -X GET http://<manager-ip>:<port>/containers/<container-id or container-name>/logs?stderr=1&stdout=1&
What the docker run
command would normally do, is to create a container and then start it.
In this example you are going to create a hello-world
container, then start it and finally check info about it (including the status, node name, etc). Ensure you replace the fields between <
and >
with the correct information.
- Create the hello-world container:
curl -H "Content-Type: application/json" -X POST -d '{"Hostname": "hello-world-node", "Image": "hello-world"}' http://<manager-ip>:<port>/containers/create?name=<container-name>
- Start the hello-wold container by its name:
curl -X POST -H "Content-Type: application/json" -d '{}' http://<manager-ip>:<port>containers/<container-name>/start
- Query your node by its name:
curl -X GET http://<manager-ip>:<port>/containers/<container-name>/json
- List images in the docker host
docker images
- Run an image in a container
docker run <image-name>
- Get the containers running on your host at the moment, with the -a option to see stopped containers too
docker ps [-a]
- Stop a container using its id
docker stop <container-id>
- Remove a container, with the -f option to force the container to stop if it is running
docker rm [-f] <container-id>
- Print the logs of the container
docker logs <container-id>
- Attach to a container
docker attach <container-id>
- Add TLS authentication for Security
- Define Affinity rules. This is useful to for example to guarantee two highly resource consuming containers don’t get scheduled on the same machine
- Exit from the VM
- Execute
vagrant destroy
from the same directory we have been working on.