Skip to content

Instantly share code, notes, and snippets.

@ravibhure
Last active December 7, 2018 17:57
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ravibhure/de747e2292068811002a to your computer and use it in GitHub Desktop.
Save ravibhure/de747e2292068811002a to your computer and use it in GitHub Desktop.
Docker for CentOS
# Disable selinux as it interferes with functionality of LXC
$ setenforce 0
$ echo 'SELINUX=disabled' > /etc/selinux/config
# Download and setup Fedora EPEL Repository
$ yum -y install http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm
# Setup hop5.in repository
$ wget http://www.hop5.in/yum/el6/hop5.repo -O /etc/yum.repos.d/hop5.repo
# Install build tools.
$ yum -y install gcc make gcc-c++ zlib-devel openssl-devel readline-devel sqlite-devel perl wget dkms nfs-utils
# Enable ip forwarding
$ sysctl -w net.ipv4.ip_forward=1
# Disable require tty
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
# Make ssh faster by not waiting on DNS
echo "UseDNS no" >> /etc/ssh/sshd_config
# Install docker-io package
$ yum -y install docker-io
# Check the package is installed correctly
$ docker -h
Example:
[root@localhost ~]# docker -h
Usage of docker:
-D=false: Debug mode
-H=[unix:///var/run/docker.sock]: tcp://host:port to bind/connect to or unix://path/to/socket to use
-api-enable-cors=false: Enable CORS requests in the remote api.
-b="": Attach containers to a pre-existing network bridge. Use 'none' to disable container networking
-d=false: Daemon mode
-dns="": Set custom dns servers
-g="/var/lib/docker": Path to graph storage base dir.
-p="/var/run/docker.pid": File containing process PID
-r=false: Restart previously running containers
# Add cgroup filesystem to /etc/fstab , so that docker will work correctly
FIXME: Per "Peter Zimmerman" a reboot is needed to actually mount /sys/fs/cgroup (due to the kernel doesn't have cgroup support). So, the manual mount step is not really needed. As its used only upon reboot.
$ echo "none /sys/fs/cgroup cgroup defaults 0 0" >> /etc/fstab
# Reboot the system
# Once system is up and running, make sure you are on right kernel
$ uname -r
$ grep aufs /proc/filesystems
Example:
[root@localhost ~]# grep aufs /proc/filesystems
nodev aufs
# Start the docker.io in daemon mode (in a different terminal)
$ docker -d
Example:
[root@localhost ~]# docker -d
2014/06/09 03:53:52 WARNING: Your kernel does not support cgroup swap limit.
2014/06/09 03:53:52 Listening for HTTP on /var/run/docker.sock (unix)
# Print hello world from a centos 6.4 container.
$ docker run centos:6.4 echo "hello world"
Example:
[root@localhost ~]# docker run centos:6.4 echo "hello world"
2014/06/09 03:55:13 POST /v1.4/containers/create
2014/06/09 03:55:13 POST /v1.4/containers/c6bc9e80097e/start
2014/06/09 03:55:13 POST /v1.4/containers/c6bc9e80097e/attach?logs=1&stderr=1&stdout=1&stream=1
hello world
# Ping from inside the container
$ docker -dns '8.8.8.8' run centos:6.4 ping -c 3 yahoo.com
Example:
[root@localhost ~]# docker -dns '8.8.8.8' run centos:6.4 ping -c 3 yahoo.com
2014/06/09 03:56:41 POST /v1.4/containers/create
2014/06/09 03:56:41 POST /v1.4/containers/c40a1244f9bc/start
2014/06/09 03:56:41 POST /v1.4/containers/c40a1244f9bc/attach?logs=1&stderr=1&stdout=1&stream=1
PING yahoo.com (98.138.253.109) 56(84) bytes of data.
64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=1 ttl=48 time=323 ms
64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=2 ttl=48 time=329 ms
64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=3 ttl=49 time=302 ms
--- yahoo.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2304ms
rtt min/avg/max/mdev = 302.032/318.318/329.656/11.807 ms
TROUBLESHOOTING
# DNS/Networking Errors inside the docker
Example:
[root@localhost ~]# docker -dns="8.8.8.8" run centos:6.4 yum install hiphop-php
2014/06/09 03:56:30 POST /v1.4/containers/create
2014/06/09 03:56:30 POST /v1.4/containers/6d9fef14bd1a/start
2014/06/09 03:56:30 POST /v1.4/containers/6d9fef14bd1a/attach?logs=1&stderr=1&stdout=1&stream=1
Loaded plugins: fastestmirror
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os error was
14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
Solution:
# Please issue the following commands, so that docker and its environment will be reset and above issue will be taken care of.
$ pkill docker
$ iptables -t nat -F
$ ifconfig docker0 down
$ brctl delbr docker0
$ docker -d
-:) You are now ready to rock with Docker
Misc:
# A Vagrantfile which, once booted, will have docker ready to go:
https://gist.github.com/ravibhure/b93fd320991da744790a
# Here is version of the init script:
https://gist.github.com/ravibhure/f65fedde194d4d49f82f
# And here is a openstack version which will give the nova group pemrissions to execute docker:
https://gist.github.com/ravibhure/b6f90160488b31aeb162
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment