Installing Docker and Docker-Compose on CentOS with Ansible

Here is the fresh installation of docker on CentOS. You can change the docker-compose verison to the latest.

Just create a yml file with following lines.

- name: install docker on fresh server
  hosts: localhost
  gather_facts: false
  
  tasks:
    - name: Get some utils installed and repo added
      shell: yum install -y yum-utils; yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    - name: install docker/git
      yum:
       name:
        - docker-ce
        - docker-ce-cli
        - containerd.io
        - git
       state: latest
    - name: kill firewall
      service:
       name: firewalld
       enabled: no
       state: stopped
    - name: Enable service
      service:
       name: docker
       enabled: yes
       state: started
    - name: Grab docker compose
      shell: curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose; chmod +x /usr/local/bin/docker-compose

Save it and execute like below.

 ansible-playbook install_docker.yml

You can verify the installation with

docker –version

docker-compose –version

Test with following command

docker run hello-world

 

Ok, that’s it!

This entry was posted in Docker, Linux and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *