1

I have RHEL 7.5 Linux EC2 machine.It has below userdata.

#cloud-config
rumcmd:
- hostname "2CPV-PQ-XX6901"
- echo "2CPV-PQ-XX6901" > /etc/hostname
- authconfig --update --disablesssd --disablesssdauth --disablemkhomedir
- echo "sudo /root/init_bootstrap.sh > /root/init_boot.log 2>&1" | at -m now + 8 minute
- service restart sshd

I want to run below two commands automatically on reboot

 sudo HTTPS_PROXY= http://someproxy.xxx.com:8080 dockerd &
 sudo chmod 666 /var/run/docker.sock

I have added the above commands in /etc/rc.local but when i reboot it looks like it doesn't run the command as docker is not working.

Please suggest where i can provide these two commands so that docker deamon runs automatically on every reboot.

0

If you want to run docker on boot your best bet is using the official package that comes with the ready to use systemd files.

Something like this should do:

export https_proxy=http://someproxy.xxx.com:8080

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

yum install docker-ce docker-ce-cli containerd.io

Now you have to set the proxy in the systemd docker config:

mkdir -p /etc/systemd/system/docker.service.d
cat > /etc/systemd/system/docker.service.d/http-proxy.conf << __EOF__
[Service]
Environment="HTTP_PROXY=${https_proxy}"
Environment="HTTPS_PROXY=${https_proxy}"
Environment="NO_PROXY=169.254.169.254,169.254.170.2"
__EOF__

You should also add the ec2-user to the docker group, then you won't need to change the /var/run/docker.sock permissions:

usermod -a -G docker ec2-user

All that can be done from the EC2 User Data script. In fact the above is a copy and paste from one of mine templates.

Then reboot and it should all work as expected.

Hope that helps :)

1
  • my shops restrictions prevent me from using yum and hence i have installed docker using binaries. – AWS_Beginner Jun 2 '20 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.