8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | 21c | 23c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux
Home » Articles » Linux » Here
Docker : Install Docker on Oracle Linux 7 (OL7)
This article demonstrates how to install Docker on Oracle Linux 7 (OL7) using a BTRFS file system.
- Assumptions
- Install Docker
- Configure BTRFS
- Finish Docker Setup
- Docker Commands as Non-Root User
- Experimental Features
- Troubleshooting
Related articles.
Assumptions
This article makes the following assumptions.
- You have a server (physical or virtual) with Oracle Linux 7 (OL7) installed. This is described here.
- You have a separate partition to hold the images and containers. In this article we have a separate virtual disk.
Install Docker
Enable all the required repositories. To do this you are going to need the yum-utils
package.
yum install -y yum-utils zip unzip yum-config-manager --enable ol7_optional_latest yum-config-manager --enable ol7_addons yum install -y oraclelinux-developer-release-el7 yum-config-manager --enable ol7_developer
Install Docker and BTRFS.
yum install -y docker-engine btrfs-progs btrfs-progs-devel
Configure BTRFS
By default the containers are created under the "/var/lib/docker", so you really need to house this on a separate disk or in a separate partition, preferably using BTRFS as the file system.
I have a second LUN with a device named "/dev/sdb". I could build the file system on this disk directly, but I prefer to partition the disks with a single partition using fdisk. These responses will create a new partition using the whole of the disk ("n", "p", "return", "return", "return", "w").
# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x2ccc116e. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): First sector (2048-25165823, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-25165823, default 25165823): Using default value 25165823 Partition 1 of type Linux and of size 12 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. #
Make the BTRFS file system on the "sdb1" partition. The Oracle Linux 7 Configuring Docker Storage manual describes how to use the docker-storage-config
utility to do this with a single command.
# docker-storage-config -s btrfs -d /dev/sdb1 Creating 'btrfs' file system on: /dev/sdb1 #
We can see the file system is added to the "/etc/fstab" file and has been mounted under "/var/lib/docker" by the utility.
# cat /etc/fstab # # /etc/fstab # Created by anaconda on Tue Nov 14 11:49:55 2017 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/ol-root / xfs defaults 0 0 UUID=196ae589-c060-46b9-87dc-49d3ed2b01e7 /boot xfs defaults 0 0 /dev/mapper/ol-swap swap swap defaults 0 0 UUID=10dbd6c1-8ae4-420e-91d8-b021f334e82b /var/lib/docker btrfs defaults 0 0 # added by docker-storage-config # # df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 7.7G 0 7.7G 0% /dev tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 7.8G 25M 7.7G 1% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/mapper/ol-root 45G 25G 21G 55% / /dev/sda1 497M 291M 206M 59% /boot tmpfs 1.6G 12K 1.6G 1% /run/user/42 tmpfs 1.6G 0 1.6G 0% /run/user/0 /dev/sdb1 100G 17M 98G 1% /var/lib/docker #
If we didn't have access to the docker-storage-config
utility we could have used the following commands.
# mkfs.btrfs -f -L docker1 /dev/sdb1 # systemctl stop docker.service # rm -Rf /var/lib/docker # mkdir /var/lib/docker # echo "LABEL=docker1 /var/lib/docker btrfs defaults 0 0" >> /etc/fstab # mount /var/lib/docker
Finish Docker Setup
Enable and start the Docker service.
# systemctl enable docker.service # systemctl start docker.service
You can get information about docker using the following commands.
# systemctl status docker.service # docker info # docker version
You are now ready to start using Docker!
Docker Commands as Non-Root User
Docker commands run as the "root" user. You have three choices when if comes to running docker commands.
- Run the docker commands from the root user.
- Allow another user to perform "sudo" on the docker command, so all commands are run using "sudo docker ...".
- Create a group called docker and assign that to the user you want to run docker commands from. The documentation says, "Warning: The docker group grants privileges equivalent to the root user", so we should avoid this.
In this case we want to run the docker commands from a user called "docker_user", so we add an entry in the "/etc/sudoers" file and use an alias in the user's ".bash_profile" file so we don't have to keep typing the "sudo" command.
# useradd docker_user # echo "docker_user ALL=(ALL) NOPASSWD: /usr/bin/docker" >> /etc/sudoers # echo "alias docker=\"sudo /usr/bin/docker\"" >> /home/docker_user/.bash_profile # su - docker_user $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES $
Experimental Features
If you want to try the experimental features, you will need to enable them for the Docker engine. To do this on Oracle Linux edit the "/etc/sysconfig/docker" file and append "--experimental=true" to the OPTIONS
setting.
OPTIONS='--selinux-enabled --experimental=true'
Then restart the Docker service.
# systemctl restart docker.service
Troubleshooting
The first time you attempt the pull down a new image you may see the following type of error.
FATA[0000] Get https://index.docker.io/v1/repositories/library/httpd/images: dial tcp: lookup index.docker.io: no such host
Assuming you have a valid internet connection, the problem will probably be fixed by restarting the Docker service.
# systemctl restart docker.service
For more information see:
Hope this helps. Regards Tim...