Tuesday, January 16, 2018

How to install and setup Docker on RHEL 7/CentOS 7

How
do I install and setup Docker container on an RHEL 7 (Red Hat
Enterprise Linux) server? How can I setup Docker on a CentOS 7? How to
install and use Docker CE on a CentOS Linux 7 server?
Docker is free and open-source software. It automates the deployment of
any application as a lightweight, portable, self-sufficient container
that will run virtually anywhere. Typically you develop software on your
laptop/desktop. You can build a container with your app, and it can
test run on your computer. It will scale in cloud, VM, VPS, bare-metal
and more. There are two versions of docker. The first one bundled with
RHEL/CentOS 7 distro and can be installed with the yum. The second
version distributed by the Docker project called docker-ce (community
free version) and can be installed by the official Docker project repo.
The third version distributed by the Docker project called docker-ee
(Enterprise paid version) and can be installed by the official Docker
project repo. This page shows how to install, setup and use Docker or Docker CE on RHEL 7 or CentOS 7 server and create your first container.

How to install and use Docker on RHEL 7 or CentOS 7 (method 1)

The procedure to install Docker is as follows:

Open the terminal application or login to the remote box using ssh command:ssh user@remote-server-name

How to run docker commands

Get system-wide information about Docker

docker info

Getting help

docker help | more Sample outputs: Run 'docker COMMAND --help' for more information on a command:docker ps --help docker cp --help

How to test your docker installation

Docker
images are pulled from docker cloud/hub such as docker.io or
registry.access.redhat.com and so on. Type the following command to
verify that your installation working:docker run hello-world Sample outputs:

How to search for Docker images

Now
you have working Docker setup. It is time to find out images. You can
find images for all sort of open source projects and Linux
distributions. To search the Docker Hub/cloud for nginx image run:docker search nginx Sample outputs:Click to enlarge

How to install Docker nginx image

To pull an image named nginx from a registry, run:docker pull nginx Sample outputs:

How to run Docker nginx image

Now you pulled image, it is time to run it:docker run --name my-nginx-c1 --detach nginx Say you want to host simple static file hosted in /home/vivek/html/ using nginx container:docker run --name my-nginx-c2 -p 80:80 -v /home/vivek/html/:/usr/share/nginx/html:ro -d nginx Where,