0% found this document useful (0 votes)
50 views

Docker

This document outlines steps to install Docker Engine on Ubuntu, create Apache and Nginx containers, and pull related images from DockerHub. It uses Ansible playbooks to update packages, add Docker keys and repositories, install Docker packages, create detached containers publishing ports, and pull specified images.

Uploaded by

Rohith
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Docker

This document outlines steps to install Docker Engine on Ubuntu, create Apache and Nginx containers, and pull related images from DockerHub. It uses Ansible playbooks to update packages, add Docker keys and repositories, install Docker packages, create detached containers publishing ports, and pull specified images.

Uploaded by

Rohith
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

ubuntu@ip-172-31-35-77:~$ cat DockerEngine.yaml container.yaml image.

yaml
---
- name: Installing Docker Engine
hosts: all
become: true
tasks:
#sudo apt-get update
- name: updating the machine
apt:
update_cache: yes
#sudo apt-get install ca-certificates curl gnupg
- name: Installing ca-certificates, curl, gnupg
apt:
name:
- ca-certificates
- curl
- gnupg
#sudo install -m 0755 -d /etc/apt/keyrings
- name: Create a directory for Docker keys
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
#curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o
/etc/apt/keyrings/docker.gpg
- name: Download and install the GPG key for Docker
shell: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --
dearmor -o /etc/apt/keyrings/docker.gpg
#sudo chmod a+r /etc/apt/keyrings/docker.gpg
- name: Changing permissions for DockerGPG keys
file:
path: /etc/apt/keyrings/docker.gpg
mode: '0644'
#echo \
# "deb [arch="$(dpkg --print-architecture)"
signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
# "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
# sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
#sudo apt-get update
- name: Add the repository to the apt sources
shell: echo "deb [arch="$(dpkg --print-architecture)"
signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | sudo tee
/etc/apt/sources.list.d/docker.list > /dev/null
#sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin
docker-compose-plugin
- name: Installing docker and its dependencies
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
update_cache: yes
state: latest
---
- name: Creating apache2 and nginx containers
hosts: all
become: true
tasks:
- community.docker.docker_container:
name: "apache-container"
image: "ubuntu/apache2"
detach: yes
state: started
publish_all_ports: yes
- community.docker.docker_container:
name: "nginxcontainer"
image: "nginx"
detach: yes
state: started
publish_all_ports: yes
---
- name: Pulling apache2 and nginx images from DockerHub
hosts: all
become: true
tasks:
- community.docker.docker_image:
name: "ubuntu/apache2"
source: pull
- community.docker.docker_image:
name: "nginx"
source: pull

You might also like