I want to create instances in Openstack that will have Docker in them already installed prior to ssh to them. So naturally I got interested in Cloud-init technology because it allows us to install packages on virtual machines during first boot time. So now I'm trying to install Docker on my instances during boot time, here is my code that I'm passing to the user data;
#cloud-config
packages:
- docker.io
This doesn't work obviously, so how can I make it work?
Docker in cloud computing is a tool that is used to automate the deployment of applications in an environment designed to manage containers. It is a container management service. These containers help applications to work while they are being shifted from one platform to another.
If you want to install from the Docker repositories on an Ubuntu instance, and you don't especially like the idea of downloading and executing an arbitrary shell script, all you need is this:
#cloud-config
apt:
sources:
docker.list:
source: deb [arch=amd64] https://download.docker.com/linux/ubuntu $RELEASE stable
keyid: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
packages:
- docker-ce
- docker-ce-cli
cloud-init already knows how to get a GPG key, how to add an APT source (even if it is HTTPS), how to update APT before installing packages, and how to do all the other stuff you'll find in various shell script heavy ways of doing this.
If Docker should ever change their repo signing key, you can satisfy yourself that the change is legitimate and then get the new fingerprint with something like:
$ curl -sL https://download.docker.com/linux/ubuntu/gpg | gpg
gpg: keybox '/home/ubuntu/.gnupg/pubring.kbx' created
gpg: WARNING: no command supplied. Trying to guess what you mean ...
pub rsa4096 2017-02-22 [SCEA]
9DC858229FC7DD38854AE2D88D81803C0EBFCD88
uid Docker Release (CE deb) <[email protected]>
sub rsa4096 2017-02-22 [S]
CAUTION: You should not use the Docker Convenience script (get.docker.com
), it carries a warning for production environments:
Using these scripts is not recommended for production environments
Here are three ways to install Docker on Ubuntu using cloud-init for all environments that don't use the Docker Convenience script.
#cloud-config
apt:
sources:
docker.list:
source: deb [arch=amd64] https://download.docker.com/linux/ubuntu $RELEASE stable
keyid: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
packages:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
- docker-ce
- docker-ce-cli
- containerd.io
# Enable ipv4 forwarding, required on CIS hardened machines
write_files:
- path: /etc/sysctl.d/enabled_ipv4_forwarding.conf
content: |
net.ipv4.conf.all.forwarding=1
# create the docker group
groups:
- docker
# Add default auto created user to docker group
system_info:
default_user:
groups: [docker]
#cloud-config
packages:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
# Enable ipv4 forwarding, required on CIS hardened machines
write_files:
- path: /etc/sysctl.d/enabled_ipv4_forwarding.conf
content: |
net.ipv4.conf.all.forwarding=1
# create the docker group
groups:
- docker
# Install Docker, for production, consider pinning to stable versions
runcmd:
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
- add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- apt-get update -y
- apt-get install -y docker-ce docker-ce-cli containerd.io
- systemctl start docker
- systemctl enable docker
# Add default auto created user to docker group
system_info:
default_user:
groups: [docker]
#cloud-config
packages:
- docker.io
# create the docker group
groups:
- docker
# Add default auto created user to docker group
system_info:
default_user:
groups: [docker]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With