This tutorial will show you how to install Docker and Docker Swarm on CentOS7. This tutorial is for Docker Version 1.11 and I use Vagrant and VirtualBox to create CentOS 7 in Virtual Machine.
Create a Vagrantfile for CentOS7
1 2 3 4 5 6 7 8 9 10 11 |
Vagrant.configure(2) do |config| config.vm.box = "centos/7" config.vm.synced_folder ".", "/vagrant", disabled: true config.vm.network "private_network", ip: "172.20.20.21" config.vm.provider "virtualbox" do |vb| vb.gui = false vb.memory = 2048 vb.cpus = 2 end end |
Turn on your Virtual Machine with command:
1 |
vagrant up |
After finishing creating CentOS server, you access the server via SSH by command:
1 |
vagrant ssh |
Docker
Go to root account:
1 |
sudo su |
In the next step, we will install Docker Engine following the official tutorial of Docker.
Add Docker Repository into CentOS
1 2 3 4 5 6 7 8 |
sudo tee /etc/yum.repos.d/docker.repo <<-'EOF' [dockerrepo] name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/ enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg EOF |
Running the installation
1 |
sudo yum install docker-engine |
Start Docker Service
1 |
sudo service docker start |
Enable Docker run on OS Start
1 |
sudo service enable docker |
Docker Swarm
Installing Docker Swarm via Docker Pull
1 |
docker pull swarm |
Open Docker Service Configuration file
1 |
vi /etc/systemd/system/multi-user.target.wants/docker.service |
In the line contains ExecStart, we add text as below
1 |
-H tcp://0.0.0.0:2375 |
And now, reload Docker Service
1 2 |
systemctl daemon-reload systemctl restart docker |
Now we can run Swarm Node
1 2 3 |
docker run -d --name swarm_joiner swarm join \ --addr=172.20.20.21:2375 \ token://acdb9dfa3ea6da0b0cfb2c819385fcd3 |
And running Swarm Manage
1 |
docker run -d -p 12375:2375 swarm manage token://acdb9dfa3ea6da0b0cfb2c819385fcd3 |
Finally, verify your work
1 |
docker -H :12375 info |
Video
Thanks for your reading!!!