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
Type the following command to install Docker via yum provided by Red Hat: sudo yum install docker
Type the following command to install the latest version of Docker CE (community edition): sudo yum remove docker docker-common docker-selinux docker-engine sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo yum install docker-ce
Let us see all info in details along with examples.
How to install Docker on CentOS 7 / RHEL 7 using yum
Type the following yum command: $ sudo yum install docker
How to install Docker CE on CentOS 7 (method 2)
First remove older version of docker (if any): $ sudo yum remove docker docker-common docker-selinux docker-engine-selinux docker-engine docker-ce Next install needed packages: $ sudo yum install -y yum-utils device-mapper-persistent-data lvm2 Configure the docker-ce repo: $ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
How to find out info about Docker network bridge and IP addresses
Default network bridge named as docker0 and is assigned with an IP address. To find this info run the following ip command: $ ip a $ ip a list docker0 Sample outputs:
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:cd:c0:6d:4a brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
How to run docker commands
The syntax is: docker command docker command arg docker [options] command arg docker help | more
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,
--name my-nginx-c1 : Assign a name to the container
--detach : Run container in background and print container ID
-v /home/vivek/html/:/usr/share/nginx/html:ro : Bind mount a volume
-p 80:80 : Publish a container's port(s) to the host i.e redirect all traffic coming to port 80 to container traffic
Go ahead and create a file named index.html in /home/vivek/html/: echo 'Welcome. I am Nginx server locked inside Docker' > /home/vivek/html/index.html Test it: curl http://your-host-ip-address/ curl 192.168.122.188 Sample outputs:
Welcome. I am Nginx server locked inside Docker
How to list running Docker containers
docker ps docker ps -a Sample outputs:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bb9d85a56a92 nginx "nginx -g 'daemon of…"55 seconds ago Up 54 seconds 0.0.0.0:80->80/tcp my-nginx-c2
fe0cdbc0225a nginx "nginx -g 'daemon of…" About a minute ago Up About a minute 80/tcp my-nginx-c1
You can use CONTAINER ID to stop, pause or login into the container.
How to run a command in a running container
Run ls /etc/nginx command for my-nginx-c1 container docker exec fe0cdbc0225a ls /etc/nginx OR docker exec my-nginx-c1 ls /etc/nginx Want to gain bash shell for a running container and make changes to nginx image? docker exec -i -t fe0cdbc0225a bash OR docker exec -i -t my-nginx-c1 bash
How to stop running containers
docker stop my-nginx-c1 OR docker stopfe0cdbc0225a
How to remove docker containers
docker rm my-nginx-c1 docker ps -a And there you have it, Docker installed and running on a CentOS 7 or RHEL 7 server. For more info see the following resources:
Download samples Table of Contents 1. Introduction 2. Background 3. Sexy Features 3.1. Extension Methods 3.2. Anonymous Type 3.3. Delegate 3.4. Lambda Expression 3.5. Async-Await Pair 3.6. Generics 4. Conclusion 1. Introduction C# is a very popular programming language. It is mostly popular in the .NET arena. The main reason behind that is the C# language contains so many useful features. It is actually a multi-paradigm programming language. Q. Why do we call C# a muti-paradigm programming language? A. Well, C# has the following characteristics: Strongly typed Object Oriented Functional Declarative Programming Imperative Programming Component based Programming Dynamic Programming ...
Certain questions about Kubernetes seem to come up again and again: What’s up with this init container stuff? What’s a CNI plugin? Why is Kubernetes complaining about pods not finishing initialisation? Kubernetes is a complex system with a simple overall purpose: run user workloads in a way that permits the authors of the workloads to not care (much) about the messy details of the hardware underneath. The workload authors are supposed to be able to just focus on Pods and Services; in turn, Kubernetes is meant to arrange things such that workloads get mapped to Pods, Pods get deployed on Nodes, and the network in between looks flat and transparent. This is simple to state, but extremely complex to implement in practice. (This is an area where Kubernetes is doing a great job of making things complex for the Kubernetes implementors so that they can be easier for the users – nicely done!) Under the hood, Kubernetes is leaning heavily on a number of technologies to ma...
Brief introduction to Linux kernel and shell Users new to Linux will want to familiarise themselves with the following: terminal is a program that opens a window and lets you interact with the shell shell is a program that takes commands from the keyboard and gives them to the operating system to perform. Bourne-Again shell, usually referred to as bash, which is the default shell for most Linux distributions. When you first login to a server, you will be dropped into the command prompt, or shell prompt, which is where you can issue commands to the server. The shell will forward its input (usually, from your own key presses) to the running program’s stdin, and it will forward the program’s output (stdout and stderr) to its own output (usually displayed on your screen). The shell is an interface that translates commands into some low-level calls to the kernel. kernel is the essential center of a computer operating system, the core that provides basic services f...
Thank you for sharing very useful blog!!!!
ReplyDeleteKubernetes Online Training
Docker Training
Docker Online Training