Docker is a container technology which has gained popularity due to its light-weight nature. Docker is native to Linux and it has adopted the Linux features. Dockers can also be installed on other operating systems such as Mac OS-X, Oracle Linux 6 & 7 and Windows.
In this chapter, we will learn about Docker installation, initialization and running in various platforms like Windows, Oracle Linux and Mac OS-X. Boot-2-Docker, Windows Docker client, btrfs file system, Unbreakable Linux Network and Oracle Public Yum are the famous technologies which will be used for these installations on various operating systems. Instructions about upgrading and un-installation of Docker on these operating systems have also been discussed in this chapter.
Docker can be installed by Boot2Docker mainly for running docker commands in the command-line. If you are familiar with command-line, you can choose this kind of installation else you can choose Docker project from GitHub.
There is another alternative application called ‘Kitematic’ which allows you in installing Docker and to run containers using GUI or graphical user interface.
Docker cannot be run natively in OS X as Linux specific features are adopted by Docker daemon. You must thus install Boot2Docker tool. This tool has VirtualBox or Virtual Machine (VM).
The Boot2Docker application has the advantage of Linux virtual machine’s light weight nature mainly for running Docker daemon on the operating system, Mac OS X. From the main memory RAM, VirtualBox’s Virtual machine runs. The VirtualBox is just around 24 Megabytes of download which gets booted in less time like 5 seconds.
In order for Boot2Docker to run, your Mac OS must have OS X 10.6 version called ‘Snow Leopard” or even more recent.
During Docker installation in Linux kernel, your system acts as both Docker host and the local host. Local host is your own system according to networking terminology. The Docker host is the system where the Docker containers are running.
In traditional Linux installation, Docker daemon, Docker client and the Docker containers will run on the local host. The Docker container ports can be addressed with the help of local host address. For example: localhost : 9000 or 0.0.0.2:4567. In Mac OS X installation, docker daemon runs inside virtual machine of Linux supported by Boot2Docker.
In Mac OS X, the address of Linux virtual machine is the Docker host’s address. Virtual machine (VM) is assigned an IP address when the boot2docker processes get started. The container map to ports is present under boot2docker ports in the virtual machine.
Docker Installation
1. Go to the boot2docker for Mac OS X installer web page.
2. Then download Boot2Docker by selecting Boot2Docker-y.y.y.pkg from the
“Downloads”.
3. Double-click the package downloaded to install Boot2Docker application.
The Boot2Docker installer for Mac OS-X will place the VirtualBox and
Boot2Docker in your “Applications” directory.
The installer also places the boot2docker and docker binary files in your /usr/localhost/bin folder.
For running a Docker container, you need to first run the boot2docker Virtual Machine and supply docker commands such as create, manage and load for the Docker containers. The Boot2Docker can be launched whether from command line of your local host or from the ‘Applications’ folder.
If you are finished with launching of Boot2Docker application from the “Applications” folder, the Boot2Docker will:
Once the launching of Boot2Docker completes, docker commands can be run. The best way to verify if your set up is complete is by running the “hi-all” container.
Note: Though it is a practice among programmers to name the first program or first container as “hello-world”, we have used a different name here, just for a change. The container names are user-defined.
$ docker run hi-all
Unable to find image ‘hi-all:latest’ locally
822247ae4d5b: Pull is complete
13bbdcc63499: Pull is complete
D23456fa75d01: Pull is complete
Hi-all:latest: The image you pulled is verified.
Important: Image verification is a technical preview characteristic and must not be dependable for providing security.
Status: Completed Download of newer image for hello-world:latest Hi from Docker.
The above message indicates that the Docker installation seems to be working perfectly.
For generating the above message, Docker uses the following steps:
1. To begin, Docker client has communicated with Docker daemon.
2. By assuming that Docker image was not readily available in local host container, it has pulled the image from the public storage, ‘Docker Hub’.
3. From that Docker image, a new container is created. The newly created Docker container is capable of running the executable code which is producing the above message as output.
4. The Docker daemon has passed that output message to Docker client or your localhost and this is displayed in your terminal. If you wish to try something more challenging, you run Ubuntu container using its specific command:
If you wish to try something more challenging, you run Ubuntu container using its specific command:
Command Line
For running the Boot2Docker and initializing it through command line, follow these steps:
1. Begin by creating Boot2Docker virtual machine using ‘init’ command.
$ boot-2-docker init
The above command will create a new Boot2Docker virtual machine. It is enough if you run this command just once.
2. In order to run the Boot2Docker virtual machine:
$ boot-2-docker start
3. For Docker client, showcase the environment variables.
The address as well as specific paths would be different on your host system. In order to set environment variables, you need to perform the following in shell:
$ eval ” $ ( boot-2-docker shell-init) “
These environment variables can be set manually using the ‘export’ command that the Boot2Docker returns.
Now, run the hi-all container to check your setup.
$ docker run hi-all
1. Initiate NGINX container on DOCKER_HOST
Usually, ‘run’ command of Docker initiates a Docker container, runs it and finally exits. The –d is a flag which enables background-running of Docker container after ‘run’ command completes execution. The –p flag is used to publish all exposed ports from Docker container to the local host system. This will enable your access from Mac OS.
2. Using docker ps command, display the running docker container
CONTAINER ID: 6bf56bf675d8
IMAGE: nginx:lat
COMMAND: “nginx –g”
CREATED: daemon of 5 minutes ago
STATUS: Up 4 minutes
PORTS: 0.0.0.1:94165->343/tcp, 0.0.0.1:58156->80/tcp
NAMES: web
From here, you can view nginx server runs as a Docker daemon.
3. To display the container ports:
$ docker port web
343/tcp -> 0.0.0.1:59146
80/tcp -> 0.0.0.1:48916
This shows that the port number 60 of web container is mapped with port number 48916 on your local host.
4. Enter the “https://localhost:48916” address (localhost is 0.0.0.1) in your web browser
The above command did not work. The reason behind is that the address of DOCKER_HOST is not the address of localhost (0.0.0.1) but is the address of Boot2Docker virtual machine.
5. Obtain the address of Boot2Docker virtual machine.
$ boot2docker ip
192.167.58.102 (the default ip for docker is 192.168.59.103)
6. Enter the https://192.167.58.102:48916 address in your web browser: Done!
7. To exit and then remove the currently running nginx container:
Frequently Asked Docker Interview Questions & Answers
If you run Boot2Docker version 1.4.1 and greater, Boot2Docker can be upgraded from command line. But if you run the older versions of Boot2Docker, you need to use only the package obtained from Boot2Docker repository. In order to upgrade from version 1.4.1 or greater, follow these steps:
1. Open a new terminal on your local host.
2. Stop the running of boot-2-docker application.
3. Execute upgrade command.
Uninstalling Boot2Docker
To uninstall Boot2Docker, follow the below steps:
1. Move to Boot2Docker release page: boot2docker/osx-installer
2. From downloads, download the source code either as tar or zip format.
3. From compressed file, extract the needed source code.
4. Open a new terminal in your local system
5. Change the directory to where you have extracted the new source code.
$ cd
6. Make it sure that the script, uninstall.sh is runnable:
7. Execute the uninstall.sh script:
As the Docker technology makes use of Linux-oriented features, a light weight virtual machine is necessary to run Dockers in Windows. Docker Client for Windows can be used for managing virtualized Docker applications for running, building and managing the Docker containers.
For making this process simpler, a helpful application is designed called ‘Boot2Docker’ which is helpful in creating virtual machine of Linux in Windows to enable running of Dockers in Linux OS.
Though you are using Docker client of Windows, the Docker application with host containers will keep running in Linux. Till the Windows Docker application is built, only the Linux containers were launched from the Windows system.
1. To begin, download recent version of Docker suitable for Windows Installer.
2. Execute Windows installer, which installs VirtualBox, Docker CLinet, Git for the windows, Boot2Docker management tool and boot2docker Linux ISO.
3. Run Boot2Docker. Select Start-> Program Files -> Boot-2-Docker for Windows.
4. The start application will require you to enter ‘ssh’ key passphrase which is simple but less secured. Press enter.
5. The Boot-2-Docker begins the Unix Shell which is already configured for managing the Docker container that runs inside VM (Virtual Machine).
6. Then run the docker latest version to check if it is running properly.
Boot-2-Docker Start soon starts the shell along with environment variable properly set so that Docker can be started using soon:
Let us try hi-all example image.
To run,
$ docker-run Hello Everyone
The above command must download the ‘ Hi All’ image as well as print the message “Hi from Docker”.
Initiate the Command-line Prompt of Windows cmd.exe.
Boot-2-Docker (command) needs ssh.exe for its existence in PATH, thus bin directory of Git that comes with ssh.exe must be included to %path% which is environment variable.
Then, we can easily execute Start command of Boot-2-Docker for initiating Boot-2- Docker virtual machine. If there is an error message stating ‘machine never exists’, init command can be run. Next, copy commands for cmd.exe for setting environment variables for the window console. You are now ready for running docker commands like docker ps.
Initiate the PowerShell window and to your PATH, add ssh.exe:
After executing the ‘boot2docker start’ command, the PowerShell commands will be printed. This is to enable setting environment variables for connecting Docker inside virtual machine. After running these PowerShell commands, you can readily run commands of docker like docker ps.
Alternatively, instead of copy-pasting the environment variables on PowerShell, you can run boot2docker shellinit command for setting environment variables.
1. Download recent version of Docker for Windows installation.
2. Start running Windows installer which updates the ‘Boot2Docker management tool’.
3. For upgrading the virtual machine, you need to open the new terminal and execute
the following commands:
Boot-2-docker start
Boot-2-docker download
Boot-2-docker stop
The default user name for boot2docker is ‘docker’ and the corresponding password is ‘tcuser’.
Only a network adapter is set up in host machine using the recent release of boot2docker and this gives access to the port of container.
To run a docker container using exposed port:
This allows you to access the server ‘nginx’ with the help of IP address retrieved using:
By default, it is always 192.168.59.103 however it may be changed by Dynamic Host Control Protocol for virtual machine implementation.
Boot2Docker creates and uses private/public key pairs in the profile: %USERPROFILE%.ssh folder. For logging in, you must make use of private key from the same ssh directory.
The format of private key must be converted to a form that PUTTY uses. Using puttygen, the above can be achieved:
Window’s standard process is used in uninstalling boot2docker which helps to remove programs. The Window process never deletes docker installation file: docker install.exe. This file must be deleted by the user.
Subscription of Oracle Linux support is not needed for installing Docker in Oracle Linux.
Oracle Linux users having active support subscription: The Docker is made available for Oracle Linux 6 and 7 with ULN (Unbreakable Linux Network) either in 017_x86_64 addon or 016_x86_64 addon channel, for these users.
Oracle Linux users who do not possess active support subscription: For these users, Docker is made available either in repositories- 016_addons or 017_addons on the Oracle Public Yum.
Docker needs the usage of Unbreakable Enterprise Kernel version 3 (3.8.13) or higher versions for Oracle Linux. The kernel provides support for Docker btrfs which is a storage engine for both Oracle Linux 6 and Oracle Linux 7.
Because of the limitations with current Docker application, the Docker can run only on x86_64 infrastructure.
Using ULN network interface, activate either 017_x86_64_addon or 016_x86_64 addon channels.
The current releases of Oracle Linux 6 and 7 will be configured automatically to use Oracle Public Yum repositories during installation process. By default, these addon repositories never get launched.
For enabling the addon repository:
1. Change either
/etc/yum.repos.d/public-yum-ol7.repo
or
etc/yum.repos.d/public-yum-ol6.repo
2. Otherwise, set enabled=1 in the [ol6_addons] or the [ol7_addons].
1. Make sure that the suitable addon repository or addon channel is set enabled.
2. Making use of yum, install the Docker package:
$ sudo yum install docker
1. Initiate the Docker daemon after installation:
For Oracle Linux 6:
$ sudo service docker start
For Oracle Linux 7:
$ sudo systemctl start docker.service
2. To start Docker daemon automatically during booting:
For Oracle Linux 6:
$ sudo chkconfig docker on
For Oracle Linux 7:
$ sudo systemctl enable docker.service
If you want to insert a HTTP proxy, different partition or directory needs to be set for using Docker runtime files. Other kinds of customizations can also be made for this purpose.
Oracle Linux 6 and Oracle Linux 7 for Docker provide support for using btrfs storage machine. Before permitting support for btrfs, make sure that /var/lib/docker is loaded on btrfs file system. You can use online manuals to learn the creation and mounting of btrfs file systems.
For enabling btrfs support for Oracle Linux:
1. Make certain that you have /var/lib/docker on the btrfs file system.
2. Edit: /etc/sysconfig/docker and to OTHER_ARGS, add –s btrfs.
3. Restart the docker daemon.
For uninstalling the Docker package:
$ sudo yum -y remove docker
The above ‘remove’ command does not remove or delete containers, images, user configured files or volumes from your host computer. If you want to remove all containers, images and volumes, then run the following docker command:
$ rm -rf /var/lib/docker
You must manually remove the user made configuration files.
Docker dismounts btrfs filesystem during system shutdown
When you stop the Docker application after executing Docker with btrfs file system, the btrfs storage system gets dismounted on system shut down. You need to ensure that the btrfs file system is installed properly before restarting the Docker application.
In Oracle Linux version 7, system.mount command can be used. You can modify or change the Docker system.service as btrfs mounting depends on definition from systemd.
SElinux support for Oracle Linux 7
SElinux should be set disabled or permissive in /etc/sysconfig/selinux for using btrfs file storage machine on Oracle Linux version 7.
Docker Kubernetes Training |
OpenShift Training |
OpenShift Administration Training |
Kubernetes Administration |
Linux Certification |
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
Docker Training | Dec 24 to Jan 08 | View Details |
Docker Training | Dec 28 to Jan 12 | View Details |
Docker Training | Dec 31 to Jan 15 | View Details |
Docker Training | Jan 04 to Jan 19 | View Details |
Vinod M is a Big data expert writer at Mindmajix and contributes in-depth articles on various Big Data Technologies. He also has experience in writing for Docker, Hadoop, Microservices, Commvault, and few BI tools. You can be in touch with him via LinkedIn and Twitter.