{"id":11798,"date":"2019-03-17T11:02:23","date_gmt":"2019-03-17T11:02:23","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11798"},"modified":"2019-03-17T11:02:23","modified_gmt":"2019-03-17T11:02:23","slug":"install-docker-and-learn-basic-container-manipulation-in-centos-and-rhel-7-6","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/17\/install-docker-and-learn-basic-container-manipulation-in-centos-and-rhel-7-6\/","title":{"rendered":"Install Docker and Learn Basic Container Manipulation in CentOS and RHEL 7\/6"},"content":{"rendered":"<p>In this 3-article series, we will discuss about\u00a0<strong>Docker<\/strong>, is an open-source lightweight virtualization tool which runs at top of Operating System level, allowing users to create, run and deploy applications, encapsulated into small containers.<\/p>\n<div id=\"attachment_18447\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Install-Docker-and-Learn-Containers.png\" rel=\"attachment wp-att-18447\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18447\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Install-Docker-and-Learn-Containers.png\" alt=\"Install Docker and Learn Basic Container Manipulation\" width=\"720\" height=\"345\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Install Docker and Learn Basic Container Manipulation \u2013 Part 1<\/p>\n<\/div>\n<p>This type of Linux containers are proven to be fast, portable and secure. The processes that run in a Docker container are always isolated from the main host, preventing outside tampering.<\/p>\n<div id=\"exam_announcement\"><b>Part 1<\/b>:\u00a0<b>Install Docker and Learn Basic Container Manipulation in CentOS and RHEL 7\/6<\/b><\/div>\n<div id=\"exam_announcement\"><b>Part 2<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/install-run-and-delete-applications-inside-docker-containers\/\" target=\"_blank\" rel=\"noopener\">How to Deploy and Run Applications into Docker Containers on CentOS\/RHEL 7\/6<\/a><\/div>\n<div id=\"exam_announcement\"><b>Part 3<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/build-and-configure-docker-container-images-with-dockerfile\/\" target=\"_blank\" rel=\"noopener\">Automatically Build and Configure Docker Images with Dockerfile on CentOS\/RHEL 7\/6<\/a><\/div>\n<div id=\"exam_announcement\"><b>Part 4<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/ctop-monitor-docker-containers\/\" target=\"_blank\" rel=\"noopener\">How to Monitor Docker Containers in Linux<\/a><\/div>\n<p>This tutorial provides a starting point on how to install Docker, create and run Docker containers on\u00a0<strong>CentOS\/RHEL 7\/6<\/strong>, but barley scratches the surface of Docker.<\/p>\n<h3>Step 1: Install and Configure Docker<\/h3>\n<p><strong>1.<\/strong>\u00a0Docker binaries are incorporated into\u00a0<strong>RHEL\/CentOS 7<\/strong>\u00a0extras repositories, the installation process being pretty simple. Install Docker package by issuing the following command with root privileges:<\/p>\n<h4>Install Docker on RHEL and CentOS 7<\/h4>\n<pre># yum install docker\r\n<\/pre>\n<div id=\"attachment_18443\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Install-Docker-on-CentOS-RHEL-7.png\" rel=\"attachment wp-att-18443\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18443\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Install-Docker-on-CentOS-RHEL-7.png\" alt=\"Install Docker on CentOS and RHEL 7\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Install Docker on CentOS and RHEL 7<\/p>\n<\/div>\n<h4>Install Docker on RHEL and CentOS 6<\/h4>\n<p>To install Docker, the\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-enable-epel-repository-for-rhel-centos-6-5\/\" target=\"_blank\" rel=\"noopener\">Epel repositories<\/a>\u00a0must be enabled on your system by issuing the following command:<\/p>\n<pre># yum install epel-release\r\n# yum install docker-io\r\n<\/pre>\n<div id=\"attachment_18421\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Install-Docker-on-RHEL-CentOS-6.png\" rel=\"attachment wp-att-18421\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18421\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Install-Docker-on-RHEL-CentOS-6.png\" alt=\"Install Docker on RHEL and CentOS 6\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Install Docker on RHEL and CentOS 6<\/p>\n<\/div>\n<p><strong>2.<\/strong>\u00a0After, Docker package has been installed, start the daemon, check its status and enable it system wide using the below commands:<\/p>\n<h4>On RHEL\/CentOS 7<\/h4>\n<pre># systemctl start docker \r\n# systemctl status docker\r\n# systemctl enable docker\r\n<\/pre>\n<div id=\"attachment_18441\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Enable-Docker-on-RHEL-and-CentOS-7.png\" rel=\"attachment wp-att-18441\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18441\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Enable-Docker-on-RHEL-and-CentOS-7.png\" alt=\"Enable Docker on RHEL and CentOS 7\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Enable Docker on RHEL and CentOS 7<\/p>\n<\/div>\n<h4>On RHEL\/CentOS 6<\/h4>\n<pre># service docker start\r\n# service docker status\r\n# chkconfig docker on\r\n<\/pre>\n<div id=\"attachment_18440\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Enable-Docker-on-RHEL-CentOS-6.png\" rel=\"attachment wp-att-18440\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18440\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Enable-Docker-on-RHEL-CentOS-6.png\" alt=\"Enable Docker on RHEL and CentOS 6\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Enable Docker on RHEL and CentOS 6<\/p>\n<\/div>\n<p><strong>3.<\/strong>\u00a0Finally, run a container test image to verify if Docker works properly, by issuing the following command:<\/p>\n<pre># docker run hello-world\r\n<\/pre>\n<p>If you can see the below message, then everything is in the right place.<\/p>\n<pre><strong>\"Hello from Docker. This message shows that your installation appears to be working correctly.\"<\/strong>\r\n<\/pre>\n<div id=\"attachment_18424\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Docker-Hello-World.png\" rel=\"attachment wp-att-18424\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18424\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Docker-Hello-World.png\" alt=\"Docker Hello World\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Docker Hello World<\/p>\n<\/div>\n<p><strong>4.<\/strong>\u00a0Now, you can run a few basic Docker commands to get some info about Docker:<\/p>\n<h6>For system-wide information on Docker<\/h6>\n<pre># docker info\r\n<\/pre>\n<div id=\"attachment_18425\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Check-Docker-Info.png\" rel=\"attachment wp-att-18425\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18425\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Check-Docker-Info.png\" alt=\"Check Docker Info\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check Docker Info<\/p>\n<\/div>\n<h6>For Docker version<\/h6>\n<pre># docker version\r\n<\/pre>\n<div id=\"attachment_18426\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Check-Docker-Version.png\" rel=\"attachment wp-att-18426\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18426\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Check-Docker-Version.png\" alt=\"Check Docker Version\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check Docker Version<\/p>\n<\/div>\n<p><strong>5.<\/strong>\u00a0To get a list of all available Docker commands type docker on your console.<\/p>\n<pre># docker\r\n<\/pre>\n<div id=\"attachment_18427\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Docker-Commands.png\" rel=\"attachment wp-att-18427\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18427\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Docker-Commands.png\" alt=\"List Docker Commands\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">List Docker Commands<\/p>\n<\/div>\n<h3>Step 2: Download a Docker Image<\/h3>\n<p><strong>6.<\/strong>\u00a0In order to start and run a Docker container, first an image must be downloaded from\u00a0<a href=\"https:\/\/hub.docker.com\/\" target=\"_blank\" rel=\"nofollow noopener\">Docker Hub<\/a>\u00a0on your host. Docker Hub offers a great deal of free images from its repositories.<\/p>\n<p>To search for a Docker image, Ubuntu for instance, issue the following command:<\/p>\n<pre># docker search ubuntu\r\n<\/pre>\n<div id=\"attachment_18429\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Search-Docker-Images.png\" rel=\"attachment wp-att-18429\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18429\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Search-Docker-Images.png\" sizes=\"auto, (max-width: 1176px) 100vw, 1176px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Search-Docker-Images.png 1176w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Search-Docker-Images-768x336.png 768w\" alt=\"Search Docker Images\" width=\"1176\" height=\"515\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Search Docker Images<\/p>\n<\/div>\n<p><strong>7.<\/strong>\u00a0After you decided on what image you want to run based on your needs, download it locally by running the below command (in this case an\u00a0<strong>Ubuntu<\/strong>\u00a0image is downloaded and used):<\/p>\n<pre># docker pull ubuntu\r\n<\/pre>\n<div id=\"attachment_18430\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Download-Docker-Images.png\" rel=\"attachment wp-att-18430\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18430\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Download-Docker-Images.png\" alt=\"Download Docker Images\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Download Docker Images<\/p>\n<\/div>\n<p><strong>8.<\/strong>\u00a0To list all the available Docker images on your host issue the following command:<\/p>\n<pre># docker images\r\n<\/pre>\n<div id=\"attachment_18431\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/List-Docker-Images.png\" rel=\"attachment wp-att-18431\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18431\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/List-Docker-Images.png\" alt=\"List Docker Images\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">List Docker Images<\/p>\n<\/div>\n<p><strong>9.<\/strong>\u00a0If you don\u2019t need a Docker image anymore and you want to remove it from the host issue the following command:<\/p>\n<pre># docker rmi ubuntu\r\n<\/pre>\n<div id=\"attachment_18432\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Remove-Docker-Image.png\" rel=\"attachment wp-att-18432\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18432\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Remove-Docker-Image.png\" alt=\"Remove Docker Image\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Remove Docker Image<\/p>\n<\/div>\n<h3>Step 3: Run a Docker Container<\/h3>\n<p>When you execute a command against an image you basically obtain a container. After the command that is executing into container ends, the container stops (you get a non-running or exited container). If you run another command into the same image again a new container is created and so on.<\/p>\n<p>All the containers created will remain on the host filesystem until you choose to delete them by using the\u00a0<code>docker rm<\/code>\u00a0command.<\/p>\n<p><strong>10.<\/strong>\u00a0In order to create and run a container, you need to run a command into a downloaded image, in this case\u00a0<strong>Ubuntu<\/strong>, so a basic command would be to display the distribution version file inside the container using\u00a0<a href=\"https:\/\/www.tecmint.com\/13-basic-cat-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">cat command<\/a>, as in the following example:<\/p>\n<pre># docker run ubuntu cat \/etc\/issue\r\n<\/pre>\n<div id=\"attachment_18433\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Run-Docker-Containers.png\" rel=\"attachment wp-att-18433\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18433\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Run-Docker-Containers.png\" alt=\"Run Docker Containers\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Run Docker Containers<\/p>\n<\/div>\n<p>The above command is divided as follows:<\/p>\n<pre># docker run [local image] [command to run into container]\r\n<\/pre>\n<p><strong>11.<\/strong>\u00a0To run one of the containers again with the command that was executed to create it, first you must get the container\u00a0<strong>ID<\/strong>\u00a0(or the name automatically generated by Docker) by issuing the below command, which displays a list of the running and stopped (non-running) containers:<\/p>\n<pre># docker ps -l \r\n<\/pre>\n<div id=\"attachment_18434\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/List-Running-Docker-Containers.png\" rel=\"attachment wp-att-18434\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18434\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/List-Running-Docker-Containers.png\" alt=\"List Running Docker Containers\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">List Running Docker Containers<\/p>\n<\/div>\n<p><strong>12.<\/strong>\u00a0Once the container\u00a0<strong>ID<\/strong>\u00a0has been obtained, you can start the container again with the command that was used to create it, by issuing the following command:<\/p>\n<pre># docker start c629b7d70666\r\n<\/pre>\n<p>Here, the string\u00a0<code>c629b7d70666<\/code>\u00a0represents the container\u00a0<strong>ID<\/strong>.<\/p>\n<div id=\"attachment_18435\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Start-Docker-Containers.png\" rel=\"attachment wp-att-18435\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18435\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Start-Docker-Containers.png\" alt=\"Start Docker Containers\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Start Docker Containers<\/p>\n<\/div>\n<p><strong>13.<\/strong>\u00a0In case the container is running state, you can get it\u2019s\u00a0<strong>ID<\/strong>\u00a0by issuing\u00a0<code>docker ps<\/code>\u00a0command. To stop the running container issue\u00a0<code>docker stop<\/code>\u00a0command by specifying the container\u00a0<strong>ID<\/strong>\u00a0or auto-generated name.<\/p>\n<pre># docker stop dreamy_mccarthy\r\n# docker ps\r\n<\/pre>\n<div id=\"attachment_18436\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Start-Stop-Docker-Containers.png\" rel=\"attachment wp-att-18436\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18436\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Start-Stop-Docker-Containers.png\" sizes=\"auto, (max-width: 1182px) 100vw, 1182px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Start-Stop-Docker-Containers.png 1182w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Start-Stop-Docker-Containers-768x126.png 768w\" alt=\"Start Stop Docker Containers\" width=\"1182\" height=\"194\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Start Stop Docker Containers<\/p>\n<\/div>\n<p><strong>14.<\/strong>\u00a0A more elegant alternative so you don\u2019t have to remember the container\u00a0<strong>ID<\/strong>\u00a0would be to allocate a unique name for every container you create by using the\u00a0<code>--name<\/code>\u00a0option on command line, as in the following example:<\/p>\n<pre># docker run --name myname  ubuntu cat \/etc\/debian_version\r\n<\/pre>\n<div id=\"attachment_18437\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Add-Name-to-Docker-Container.png\" rel=\"attachment wp-att-18437\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18437\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Add-Name-to-Docker-Container.png\" sizes=\"auto, (max-width: 1043px) 100vw, 1043px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Add-Name-to-Docker-Container.png 1043w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Add-Name-to-Docker-Container-768x253.png 768w\" alt=\"Add Name to Docker Container\" width=\"1043\" height=\"343\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Add Name to Docker Container<\/p>\n<\/div>\n<p><strong>15.<\/strong>\u00a0Then, using the name that you allocated for the container, you can manipulate container (<strong>start<\/strong>,\u00a0<strong>stop<\/strong>,\u00a0<strong>remove<\/strong>,\u00a0<strong>top<\/strong>,\u00a0<strong>stats<\/strong>) further just by addressing its name, as in the below examples:<\/p>\n<pre># docker start myname\r\n# docker stats myname\r\n# docker top myname \r\n<\/pre>\n<p>Be aware that some of the above commands might display no output if the process of command that was used to create the container finishes. When the process that runs inside the container finishes, the container stops.<\/p>\n<h3>Step 4: Run an Interactive Session into a Container<\/h3>\n<p><strong>16.<\/strong>\u00a0In order to interactively connect into a container shell session, and run commands as you do on any other Linux session, issue the following command:<\/p>\n<pre># docker run -it ubuntu bash\r\n<\/pre>\n<div id=\"attachment_18438\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Start-Docker-Container-Interactive-Shell.png\" rel=\"attachment wp-att-18438\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18438\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Start-Docker-Container-Interactive-Shell.png\" alt=\"Start Docker Container Interactive Shell\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Start Docker Container Interactive Shell<\/p>\n<\/div>\n<p>The above command is divided as follows:<\/p>\n<ol>\n<li><code>-i<\/code>\u00a0is used to start an interactive session.<\/li>\n<li><strong>-t<\/strong>\u00a0allocates a tty and attaches stdin and stdout.<\/li>\n<li><code>ubuntu<\/code>\u00a0is the image that we used to create the container.<\/li>\n<li><code>bash<\/code>\u00a0(or\u00a0<strong>\/bin\/bash<\/strong>) is the command that we are running inside the Ubuntu container.<\/li>\n<\/ol>\n<p><strong>17.<\/strong>\u00a0To quit and return to host from the running container session you must type\u00a0<code>exit<\/code>\u00a0command. The\u00a0<strong>exit<\/strong>command terminates all the container processes and stops it.<\/p>\n<pre># exit\r\n<\/pre>\n<p><strong>18.<\/strong>\u00a0If you\u2019re interactively logged on container terminal prompt and you need to keep the container in running state but\u00a0<strong>exit<\/strong>\u00a0from the interactive session, you can quit the console and return to host terminal by pressing\u00a0<code>Ctrl+p<\/code>\u00a0and\u00a0<code>Ctrl+q<\/code>\u00a0keys.<\/p>\n<div id=\"attachment_18439\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Keep-Docker-Shell-Session.png\" rel=\"attachment wp-att-18439\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18439\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Keep-Docker-Shell-Session.png\" alt=\"Keep Docker Shell Session Active\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Keep Docker Shell Session Active<\/p>\n<\/div>\n<p><strong>19.<\/strong>\u00a0To reconnect to the running container you need the container\u00a0<strong>ID<\/strong>\u00a0or\u00a0<strong>name<\/strong>. Issue\u00a0<code>docker ps<\/code>\u00a0command to get the\u00a0<strong>ID<\/strong>\u00a0or\u00a0<strong>name<\/strong>\u00a0and, then, run\u00a0<code>docker attach<\/code>\u00a0command by specifying container\u00a0<strong>ID<\/strong>\u00a0or\u00a0<strong>name<\/strong>, as illustrated in the image above:<\/p>\n<pre># docker attach &lt;container id&gt;\r\n<\/pre>\n<p><strong>20.<\/strong>\u00a0To stop a running container from the host session issue the following command:<\/p>\n<pre># docker kill &lt;container id&gt;\r\n<\/pre>\n<p>That\u2019s all for basic container manipulation. In the next tutorial we will discuss how to save, delete and run a web server into a Docker container.<\/p>\n<p>Following the previous Docker article, this tutorial will discuss how to save a Docker container into a new image, remove a container and run a\u00a0<strong>Nginx<\/strong>\u00a0web server inside a container.<\/p>\n<div id=\"attachment_18477\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Install-Applications-into-Docker-Containers.png\" rel=\"attachment wp-att-18477\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18477\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Install-Applications-into-Docker-Containers.png\" alt=\"Install and Run Applications in Docker Containers\" width=\"720\" height=\"345\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Install and Run Applications in Docker Containers \u2013 Part 2<\/p>\n<\/div>\n<h4>Requirements<\/h4>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/install-docker-and-learn-containers-in-centos-rhel-7-6\/\" target=\"_blank\" rel=\"noopener\">Install Docker on CentOS and RHEL 7\/6<\/a><\/li>\n<\/ol>\n<h3>How To Run and Save a Docker Container<\/h3>\n<p><strong>1.<\/strong>\u00a0In this example we will run and save an\u00a0<strong>Ubuntu<\/strong>\u00a0based Docker container where\u00a0<strong>Nginx<\/strong>\u00a0server will be installed. But before committing any changes to container, first start the container with the below command which installs\u00a0<strong>Nginx<\/strong>\u00a0daemon into Ubuntu image:<\/p>\n<pre># docker run ubuntu bash -c \"apt-get -y install nginx\" \r\n<\/pre>\n<div id=\"attachment_18463\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Install-Nginx-on-Ubuntu-Docker-Container.png\" rel=\"attachment wp-att-18463\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18463\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Install-Nginx-on-Ubuntu-Docker-Container.png\" alt=\"Install Nginx on Ubuntu Docker Container\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Install Nginx on Ubuntu Docker Container<\/p>\n<\/div>\n<p><strong>2.<\/strong>\u00a0Next, after\u00a0<strong>Nginx<\/strong>\u00a0package is installed, issue the command\u00a0<code>docker ps -l<\/code>\u00a0to get the\u00a0<strong>ID<\/strong>\u00a0or\u00a0<strong>name<\/strong>\u00a0of the running container.<\/p>\n<pre># docker ps -l\r\n<\/pre>\n<div id=\"attachment_18464\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Docker-Container-ID-Name.png\" rel=\"attachment wp-att-18464\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18464\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Docker-Container-ID-Name.png\" alt=\"Find Docker Container ID Name\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Find Docker Container ID Name<\/p>\n<\/div>\n<p>And apply changes by running the below command:<\/p>\n<pre># docker commit 5976e4ae287c ubuntu-nginx<\/pre>\n<p>Here,\u00a0<code>5976e4ae287c<\/code>\u00a0represents the container\u00a0<code>ID<\/code>\u00a0and\u00a0<code>ubuntu-nginx<\/code>\u00a0represents the name of the newly image that has been saved with committed changes.<\/p>\n<p>In order to view if the new image has been successfully created just run\u00a0<code>docker images<\/code>\u00a0command and a listing of all saved images will be shown.<\/p>\n<pre># docker images\r\n<\/pre>\n<div id=\"attachment_18465\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Docker-Container-Changes.png\" rel=\"attachment wp-att-18465\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18465\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Docker-Container-Changes.png\" alt=\"Docker Container Changes\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Docker Container Changes<\/p>\n<\/div>\n<p>Chances are that the installation process inside the container finishes fast which leads to a non-running container (container is stopped). In this case the\u00a0<code>docker ps<\/code>\u00a0command won\u2019t show any output because no container is running.<\/p>\n<p>In order to be able to still get the container\u2019s id run\u00a0<code>docker ps -a | head -3<\/code>\u00a0to output the most recent containers and identify the container based on the command issued to create the container and the exited status.<\/p>\n<div class=\"google-auto-placed ap_container\">\n<p><strong>3.<\/strong>\u00a0Alternatively, you can actively enter container session by running\u00a0<code>docker run -it ubuntu bash<\/code>command and execute further\u00a0<code>apt-get install nginx<\/code>\u00a0command. While the command is running, detach from the container using\u00a0<code>Ctrl-p + Ctrl-q<\/code>\u00a0keys and the container will continue running even if the Nginx installation process finishes.<\/p>\n<pre># docker run -it ubuntu bash\r\n# apt-get install nginx\r\n<\/pre>\n<div id=\"attachment_18466\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Run-Docker-Container-and-Install-Nginx.png\" rel=\"attachment wp-att-18466\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18466\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Run-Docker-Container-and-Install-Nginx.png\" alt=\"Install Nginx on Docker Container\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Install Nginx on Docker Container<\/p>\n<\/div>\n<p>Then, get the running container id with\u00a0<code>docker ps<\/code>\u00a0and commit changes. When finished, re-enter to container console using\u00a0<code>docker attach<\/code>\u00a0and type\u00a0<code>exit<\/code>\u00a0to stop container.<\/p>\n<pre># docker ps\r\n# docker attach 3378689f2069\r\n# exit\r\n<\/pre>\n<div id=\"attachment_18468\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Attach-Docker-Container.png\" rel=\"attachment wp-att-18468\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18468\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Attach-Docker-Container.png\" alt=\"Attach Docker Container\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Attach Docker Container<\/p>\n<\/div>\n<p><strong>4.<\/strong>\u00a0To further test if the recently image has been committed properly (in this case\u00a0<strong>Nginx<\/strong>\u00a0service has been installed), execute the below command in order to generate a new container which will output if Nginx binary was successfully installed:<\/p>\n<pre># docker run ubuntu-nginx whereis nginx\r\n<\/pre>\n<div id=\"attachment_18469\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Generate-New-Docker-Container.png\" rel=\"attachment wp-att-18469\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18469\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Generate-New-Docker-Container.png\" alt=\"Generate New Docker Container\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Generate New Docker Container<\/p>\n<\/div>\n<p><strong>5.<\/strong>\u00a0To remove a container use the\u00a0<code>rm<\/code>\u00a0command against a container ID or name, which can be obtained using\u00a0<code>docker ps -a<\/code>\u00a0command:<\/p>\n<pre># docker ps -a\r\n# sudo docker rm 36488523933a\r\n<\/pre>\n<div id=\"attachment_18470\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Remove-Docker-Container.png\" rel=\"attachment wp-att-18470\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18470\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Remove-Docker-Container.png\" alt=\"Remove Docker Container\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Remove Docker Container<\/p>\n<\/div>\n<h3>How to Run Nginx inside Docker Container<\/h3>\n<p><strong>6.<\/strong>\u00a0In this part we will concentrate on how you can run and access a network service, such as a\u00a0<strong>Nginx<\/strong>\u00a0web server, inside Docker, using the\u00a0<code>ubuntu-nginx<\/code>\u00a0image created earlier where Nginx daemon was installed.<\/p>\n<p>The first thing that you need to do is to create a new container, map host-container ports and enter container shell by issuing the below command:<\/p>\n<pre># docker run -it -p 81:80 ubuntu-nginx \/bin\/bash\r\n# nginx &amp;\r\n<\/pre>\n<p>Here, the\u00a0<code>-p<\/code>\u00a0option exposes the host port to container port. While the host port can be arbitrary, with the condition that it should be available (no other host services should listen on it), the container port must be exactly the port that the inside daemon is listening to.<\/p>\n<p>Once you\u2019re connected to container session, start\u00a0<strong>Nginx<\/strong>\u00a0daemon in background and detach from container console by pressing\u00a0<code>Ctrl-p + Ctrl-q<\/code>\u00a0keys.<\/p>\n<div id=\"attachment_18471\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Run-Nginx-Inside-Docker-Container.png\" rel=\"attachment wp-att-18471\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18471\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Run-Nginx-Inside-Docker-Container.png\" alt=\"Run Nginx Inside Docker Container\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Run Nginx Inside Docker Container<\/p>\n<\/div>\n<p><strong>7.<\/strong>\u00a0Now, run\u00a0<code>docker ps<\/code>\u00a0to get the state of your running container. You can also view host network sockets by issuing the following command:<\/p>\n<pre># docker ps\r\nOR\r\n# netstat -tlpn \r\n<\/pre>\n<div id=\"attachment_18472\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/View-Docker-Container-Running-State.png\" rel=\"attachment wp-att-18472\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18472\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/View-Docker-Container-Running-State.png\" alt=\"View Docker Container Running State\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">View Docker Container Running State<\/p>\n<\/div>\n<p><strong>8.<\/strong>\u00a0In order to visit the page served by the Nginx container, open a browser from a remote location in your LAN and type the IP address of your machine using the HTTP protocol.<\/p>\n<div id=\"attachment_18473\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Verify-Nginx-Page.png\" rel=\"attachment wp-att-18473\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18473\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Verify-Nginx-Page.png\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Verify-Nginx-Page.png 781w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Verify-Nginx-Page-768x462.png 768w\" alt=\"Verify Nginx Running under Docker Container\" width=\"781\" height=\"470\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Verify Nginx Running under Docker Container<\/p>\n<\/div>\n<p><strong>9.<\/strong>\u00a0To stop the container run the following command followed by container ID or name:<\/p>\n<pre># docker ps\r\n# docker stop fervent_mccarthy\r\n# docker ps\r\n<\/pre>\n<div id=\"attachment_18474\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Stop-Docker-Running-Container.png\" rel=\"attachment wp-att-18474\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18474\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Stop-Docker-Running-Container.png\" alt=\"Stop Running Docker Container\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Stop Running Docker Container<\/p>\n<\/div>\n<p>As alternative to stop the running container, enter container shell command prompt and type exit to finish process:<\/p>\n<pre># docker attach fervent_mccarthy\r\n# exit\r\n<\/pre>\n<p>Be aware that using this kind of containers to run web servers or other kind of services are best suited only for development purposes or tests due to the fact that the services are only active while the container is running. Exiting the container disrupts all running services or any changes made.<\/p>\n<p>This tutorial will concentrate on how to build a custom Docker image based on\u00a0<strong>Ubuntu<\/strong>\u00a0with\u00a0<strong>Apache<\/strong>\u00a0service installed. The whole the process will be automated using a\u00a0<strong>Dockerfile<\/strong>.<\/p>\n<div id=\"attachment_18561\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Build-Configure-Docker-Images-with-Dockerfile.png\" rel=\"attachment wp-att-18561\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18561\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Build-Configure-Docker-Images-with-Dockerfile.png\" alt=\"Build Configure Docker Images with Dockerfile\" width=\"720\" height=\"345\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Build Configure Docker Images with Dockerfile \u2013 Part 3<\/p>\n<\/div>\n<p>Docker images can be automatically build form text files, named\u00a0<strong>Dockerfiles<\/strong>. A Docker file contains step-by-step ordered instructions or commands used to create and configure a Docker image.<\/p>\n<h4>Requirements<\/h4>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/install-docker-and-learn-containers-in-centos-rhel-7-6\/\" target=\"_blank\" rel=\"noopener\">Install Docker and Learn Docker Container Manipulation \u2013 Part 1<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/install-run-and-delete-applications-inside-docker-containers\/\" target=\"_blank\" rel=\"noopener\">Deploy and Run Applications under Docker Containers \u2013 Part 2<\/a><\/li>\n<\/ol>\n<p>Basically, a Docker file contains various instructions in order to build and configure a specific container based on your requirements. The following instructions are the most used, some of them being mandatory:<\/p>\n<ol>\n<li><code>FROM<\/code>\u00a0= Mandatory as first instruction in a Docker file. Instructs Docker to pull the base image from which you are building the new image. Use a tag to specify the exact image from which you are building:<\/li>\n<\/ol>\n<pre>Ex: FROM ubuntu:14.04\r\n<\/pre>\n<ol>\n<li><code>MAINTAINER<\/code>\u00a0= Author of the build image<\/li>\n<li><code>RUN<\/code>\u00a0= This instruction can be used on multiple lines and runs any commands after Docker image has been created.<\/li>\n<li><code>CMD<\/code>\u00a0= Run any command when Docker image is started. Use only one CMD instruction in a Dockerfile.<\/li>\n<li><code>ENTRYPOINT<\/code>\u00a0= Same as CMD but used as the main command for the image.<\/li>\n<li><code>EXPOSE<\/code>\u00a0= Instructs the container to listen on network ports when running. The container ports are not reachable from the host by default.<\/li>\n<li><code>ENV<\/code>\u00a0= Set container environment variables.<\/li>\n<li><code>ADD<\/code>\u00a0= Copy resources (files, directories or files from URLs).<\/li>\n<\/ol>\n<h3>Step 1: Creating or Writing Dockerfile Repository<\/h3>\n<p><strong>1.<\/strong>\u00a0First, let\u2019s create some kind of\u00a0<strong>Dockerfile<\/strong>\u00a0repositories in order to reuse files in future to create other images. Make an empty directory somewhere in\u00a0<code>\/var<\/code>\u00a0partition where we will create the file with the instructions that will be used to build the newly Docker image.<\/p>\n<pre># mkdir -p \/var\/docker\/ubuntu\/apache\r\n# touch \/var\/docker\/ubuntu\/apache\/Dockerfile\r\n<\/pre>\n<div id=\"attachment_18545\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Create-Dockerfile-Repository.png\" rel=\"attachment wp-att-18545\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18545\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Create-Dockerfile-Repository.png\" alt=\"Create Dockerfile Repository\" width=\"613\" height=\"79\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Create Dockerfile Repository<\/p>\n<p><strong>2.<\/strong>\u00a0Next, start editing the file with the following instructions:<\/p>\n<pre># vi \/var\/docker\/ubuntu\/apache\/Dockerfile\r\n<\/pre>\n<p>Dokerfile excerpt:<\/p>\n<pre>FROM ubuntu\r\nMAINTAINER  your_name  &lt;user@domain.tld&gt;\r\nRUN apt-get -y install apache2\r\nRUN echo \u201cHello Apache server on Ubuntu Docker\u201d &gt; \/var\/www\/html\/index.html\r\nEXPOSE 80\r\nCMD \/usr\/sbin\/apache2ctl -D FOREGROUND\r\n<\/pre>\n<div id=\"attachment_18546\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Dockerfile-Repository.png\" rel=\"attachment wp-att-18546\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18546\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Dockerfile-Repository.png\" alt=\"Dockerfile Repository\" width=\"687\" height=\"125\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Dockerfile Repository<\/p>\n<\/div>\n<p>Now, let\u2019s go through the file instructions:<\/p>\n<p>The first line tells us that we are building from an\u00a0<strong>Ubuntu<\/strong>\u00a0image. If no tag is submitted, say\u00a0<strong>14:10<\/strong>\u00a0for example, the latest image from\u00a0<strong>Docker Hub<\/strong>\u00a0is used.<\/p>\n<p>On the second line we\u2019ve added the\u00a0<strong>name<\/strong>\u00a0and\u00a0<strong>email<\/strong>\u00a0of the image creator. Next two\u00a0<strong>RUN<\/strong>\u00a0lines will be executed in the container when building the image and will install\u00a0<strong>Apache<\/strong>\u00a0daemon and\u00a0<strong>echo<\/strong>\u00a0some text into default apache web page.<\/p>\n<p>The\u00a0<strong>EXPOSE<\/strong>\u00a0line will instruct\u00a0<strong>Docker<\/strong>\u00a0container to listen on port\u00a0<strong>80<\/strong>, but the port will be not available to outside. The last line instructs the container to run Apache service in foreground after the container is started.<\/p>\n<p><strong>3.<\/strong>\u00a0The last thing we need to do is to start creating the image by issuing the below command, which will locally create a new Docker image named\u00a0<code>ubuntu-apache<\/code>\u00a0based on the Dockerfile created earlier, as shown in this example:<\/p>\n<pre># docker build -t ubuntu-apache \/var\/docker\/ubuntu\/apache\/\r\n<\/pre>\n<div id=\"attachment_18547\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Create-Docker-Image.png\" rel=\"attachment wp-att-18547\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18547\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Create-Docker-Image.png\" alt=\"Create Docker Image\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Create Docker Image<\/p>\n<\/div>\n<p><strong>4.<\/strong>\u00a0After the image has been created by\u00a0<strong>Docker<\/strong>, you can list all available images and identify your image by issuing the following command:<\/p>\n<pre># docker images\r\n<\/pre>\n<div id=\"attachment_18548\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-All-Docker-Images.png\" rel=\"attachment wp-att-18548\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18548\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-All-Docker-Images.png\" alt=\"List All Docker Images\" width=\"712\" height=\"277\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">List All Docker Images<\/p>\n<\/div>\n<h3>Step 2: Run the Container and Access Apache from LAN<\/h3>\n<p><strong>5.<\/strong>\u00a0In order to run the container continuously (in background) and access the container exposed services (ports) from the host or other remote machine in your LAN, run the below command on your host terminal prompt:<\/p>\n<pre># docker run -d -p 81:80 ubuntu-apache\r\n<\/pre>\n<div id=\"attachment_18549\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Docker-Container-Image.png\" rel=\"attachment wp-att-18549\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18549\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Run-Docker-Container-Image.png\" alt=\"Run Docker Container Image\" width=\"719\" height=\"201\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Run Docker Container Image<\/p>\n<\/div>\n<p>Here, the\u00a0<code>-d<\/code>\u00a0option runs the\u00a0<code>ubuntu-apache<\/code>\u00a0container in background (as a daemon) and the\u00a0<code>-p<\/code>\u00a0option maps the container port\u00a0<strong>80<\/strong>\u00a0to your localhost port\u00a0<strong>81<\/strong>. Outside LAN access to Apache service can be reached through port\u00a0<strong>81<\/strong>\u00a0only.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/20-netstat-commands-for-linux-network-management\/\" target=\"_blank\" rel=\"noopener\">Netstat command<\/a>\u00a0will give you an idea about what ports the host is listening to.<\/p>\n<p>After the container has been started, you can also run\u00a0<code>docker ps<\/code>\u00a0command to view the status of the running container.<\/p>\n<p><strong>6.<\/strong>\u00a0The webpage can be displayed on your host from command line using\u00a0<strong>curl<\/strong>\u00a0utility against your machine IP Address, localhost or docker net interface on port 81. Use\u00a0<a href=\"https:\/\/www.tecmint.com\/ip-command-examples\/\" target=\"_blank\" rel=\"noopener\">ip command<\/a>\u00a0line to show network interface IP addresses.<\/p>\n<pre># ip addr               [List nework interfaces]\r\n# curl ip-address:81    [System Docker IP Address]\r\n# curl localhost:81     [Localhost]\r\n<\/pre>\n<div id=\"attachment_18550\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Docker-IP-Address.png\" rel=\"attachment wp-att-18550\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18550\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Docker-IP-Address.png\" alt=\"Check Docker Network Interface and IP Address\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check Docker Network Interface and IP Address<\/p>\n<\/div>\n<div id=\"attachment_18551\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Docker-Apache-Webpage.png\" rel=\"attachment wp-att-18551\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18551\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Docker-Apache-Webpage.png\" alt=\"Check Docker Apache Webpage\" width=\"444\" height=\"135\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check Docker Apache Webpage<\/p>\n<\/div>\n<p><strong>7.<\/strong>\u00a0To visit the container webpage from your network, open a browser at remote location and use HTTP protocol, the IP Address of the machine where the container is running, followed by port 81 as illustrated on below image.<\/p>\n<pre>http:\/\/ip-address:81\r\n<\/pre>\n<div id=\"attachment_18552\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Docker-Container-Apache-Page.png\" rel=\"attachment wp-att-18552\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18552\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Docker-Container-Apache-Page.png\" alt=\"Check Docker Container Apache Page\" width=\"547\" height=\"195\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check Docker Container Apache Page<\/p>\n<\/div>\n<p><strong>8.<\/strong>\u00a0To get an inside of what processes are running inside the container issue the following command:<\/p>\n<pre># docker ps\r\n# docker top &lt;name or ID of the container&gt;\r\n<\/pre>\n<div id=\"attachment_18553\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Running-Docker-Processes.png\" rel=\"attachment wp-att-18553\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18553\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Check-Running-Docker-Processes.png\" alt=\"Check Running Docker Processes\" width=\"720\" height=\"400\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check Running Docker Processes<\/p>\n<\/div>\n<p><strong>9.<\/strong>\u00a0To stop the container issue\u00a0<code>docker stop<\/code>\u00a0command followed by the container ID or name.<\/p>\n<pre># docker stop &lt;name or ID of the container&gt;\r\n# docker ps\r\n<\/pre>\n<p><strong>10.<\/strong>\u00a0In case you want to assign a descriptive name for the container use the\u00a0<code>--name<\/code>\u00a0option as shown in the below example:<\/p>\n<pre># docker run --name my-www -d -p 81:80 ubuntu-apache\r\n# docker ps\r\n<\/pre>\n<div id=\"attachment_18554\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Give-Docker-Container-Name.png\" rel=\"attachment wp-att-18554\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18554\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Give-Docker-Container-Name.png\" alt=\"Give Docker Container Name\" width=\"706\" height=\"184\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Give Docker Container Name<\/p>\n<\/div>\n<p>Now you can reference the container for manipulation (start, stop, top, stats etc) only by using the assigned name.<\/p>\n<pre># docker stats my-www\r\n<\/pre>\n<div id=\"attachment_18555\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Monitor-Docker-Container-Utilization.png\" rel=\"attachment wp-att-18555\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18555\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/02\/Monitor-Docker-Container-Utilization.png\" alt=\"Monitor Docker Container Utilization\" width=\"620\" height=\"95\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Monitor Docker Container Utilization<\/p>\n<\/div>\n<h3>Step 3: Create a System-wide Configuration File for Docker Container<\/h3>\n<p><strong>11.<\/strong>\u00a0On\u00a0<strong>CentOS\/RHEL 7<\/strong>\u00a0you can create a\u00a0<strong>systemd<\/strong>\u00a0configuration file and manage the container as you normally do for any other local service.<\/p>\n<p>For instance, create a new systemd file named, let\u2019s say,\u00a0<code>apache-docker.service<\/code>\u00a0using the following command:<\/p>\n<pre># vi \/etc\/systemd\/system\/apache-docker.service\r\n<\/pre>\n<p><strong>apache-docker.service<\/strong>\u00a0file excerpt:<\/p>\n<pre>[Unit]\r\nDescription=apache container\r\nRequires=docker.service\r\nAfter=docker.service\r\n\r\n[Service]\r\nRestart=always\r\nExecStart=\/usr\/bin\/docker start -a my-www\r\nExecStop=\/usr\/bin\/docker stop -t 2 my-www\r\n\r\n[Install]\r\nWantedBy=local.target\r\n<\/pre>\n<p><strong>12.<\/strong>\u00a0After you finish editing the file, close it, reload the systemd daemon to reflect changes and start the container by issuing the following commands:<\/p>\n<pre># systemctl daemon-reload\r\n# systemctl start apache-docker.service\r\n# systemctl status apache-docker.service\r\n<\/pre>\n<p>This was just a simple example on what you can do with a simple\u00a0<strong>Dockerfile<\/strong>\u00a0but you can pre-build some pretty sophisticated applications that you can fire-up in just a matter of seconds with minimal resources and effort.<\/p>\n<h1 class=\"post-title\">ctop \u2013 Top-like Interface for Monitoring Docker Containers<\/h1>\n<p><strong>ctop<\/strong>\u00a0is a free open source, simple and cross-platform\u00a0<a href=\"https:\/\/www.tecmint.com\/12-top-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">top-like command-line tool<\/a>\u00a0for monitoring container metrics in real-time. It allows you to get an overview of metrics concerning CPU, memory, network, I\/O for multiple containers and also supports inspection of a specific container.<\/p>\n<div id=\"attachment_29957\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/Docker-Container-Monitoring.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29957\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/Docker-Container-Monitoring.gif\" sizes=\"auto, (max-width: 1195px) 100vw, 1195px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/Docker-Container-Monitoring.gif 1195w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/Docker-Container-Monitoring-768x266.gif 768w\" alt=\"Docker Container Monitoring\" width=\"1195\" height=\"414\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Docker Container Monitoring<\/p>\n<\/div>\n<p>At the time of writing this article, it ships with built-in support for\u00a0<a href=\"https:\/\/www.tecmint.com\/install-docker-and-learn-containers-in-centos-rhel-7-6\/\" target=\"_blank\" rel=\"noopener\">Docker<\/a>\u00a0(default container connector) and\u00a0<strong>runC<\/strong>; connectors for other container and cluster platforms will be added in future releases.<\/p>\n<h3>How to Install ctop in Linux Systems<\/h3>\n<p>Installing the latest release of\u00a0<strong>ctop<\/strong>\u00a0is as easy as running the following commands to download the binary for your Linux distribution and install it under\u00a0<strong>\/usr\/local\/bin\/ctop<\/strong>\u00a0and make it executable to run it.<\/p>\n<pre>$ sudo wget https:\/\/github.com\/bcicen\/ctop\/releases\/download\/v0.7.1\/ctop-0.7.1-linux-amd64  -O \/usr\/local\/bin\/ctop\r\n$ sudo chmod +x \/usr\/local\/bin\/ctop\r\n<\/pre>\n<p>Alternatively, install\u00a0<strong>ctop<\/strong>\u00a0via Docker using following command.<\/p>\n<pre>$ docker run --rm -ti --name=ctop -v \/var\/run\/docker.sock:\/var\/run\/docker.sock quay.io\/vektorlab\/ctop:latest\r\n<\/pre>\n<p><center>Once you have installed\u00a0<strong>ctop<\/strong>, you can run it to list all your containers whether active or not.<\/center><\/p>\n<pre>$ ctop\r\n<\/pre>\n<div id=\"attachment_29953\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/List-All-Docker-Containers.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29953\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/List-All-Docker-Containers.png\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/List-All-Docker-Containers.png 942w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/List-All-Docker-Containers-768x188.png 768w\" alt=\"Monitor Docker Containers\" width=\"942\" height=\"230\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Monitor Docker Containers<\/p>\n<\/div>\n<p>You can use the\u00a0<strong>Up<\/strong>\u00a0and\u00a0<strong>Down<\/strong>\u00a0arrow keys to highlight a container and click\u00a0<strong>Enter<\/strong>\u00a0to select it. You will see a menu as shown in the following screenshot. Choose\u00a0<strong>\u201csingle view\u201d<\/strong>\u00a0and click on it to inspect the selected container.<\/p>\n<div id=\"attachment_29954\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/Monitor-Docker-Container.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29954\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/Monitor-Docker-Container.png\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/Monitor-Docker-Container.png 942w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/Monitor-Docker-Container-768x157.png 768w\" alt=\"Monitor Single Docker Container\" width=\"942\" height=\"192\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Monitor Single Docker Container<\/p>\n<\/div>\n<p>The following screenshot shows the single view mode for a specific container.<\/p>\n<div id=\"attachment_29955\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/inspect-a-single-container.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29955\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/inspect-a-single-container.png\" alt=\"Inspect a Single Container\" width=\"546\" height=\"722\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Inspect a Single Container<\/p>\n<\/div>\n<p>To display active containers only, use the\u00a0<code>-a<\/code>\u00a0flag.<\/p>\n<pre>$ ctop -a \r\n<\/pre>\n<div id=\"attachment_29956\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/only-show-active-containers.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29956\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/only-show-active-containers.png\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/only-show-active-containers.png 942w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/07\/only-show-active-containers-768x157.png 768w\" alt=\"Check Active Docker Container\" width=\"942\" height=\"192\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check Active Docker Container<\/p>\n<\/div>\n<p>To display CPU as\u00a0<code>%<\/code>\u00a0of system total, use the\u00a0<code>-scale-cpu<\/code>\u00a0option.<\/p>\n<pre>$ ctop -scale-cpu\r\n<\/pre>\n<p>You can also filter containers using the\u00a0<code>-f<\/code>\u00a0flag, for example.<\/p>\n<pre>$ ctop -f app\r\n<\/pre>\n<p>Additionally, you can select initial container sort field using the\u00a0<code>-s<\/code>\u00a0flag, and see the\u00a0<strong>ctop<\/strong>\u00a0help message as shown.<\/p>\n<pre> \r\n$ ctop -h\r\n<\/pre>\n<p>Note that connectors for other container and cluster systems are yet to be added to\u00a0<strong>ctop<\/strong>. You can find more information from the\u00a0<a href=\"https:\/\/github.com\/bcicen\/ctop\" target=\"_blank\" rel=\"nofollow noopener\">Ctop Github repository<\/a>.<\/p>\n<p><strong>ctop<\/strong>\u00a0is a simple top-like tool for visualizing and monitoring container metrics in real-time. In this article, we\u2019ve expalined how to install and use ctop in Linux. You can share your thoughts or ask any questions via the comment form below.<\/p>\n<p><a style=\"font-size: 1rem;\" href=\"https:\/\/www.tecmint.com\/install-docker-and-learn-containers-in-centos-rhel-7-6\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this 3-article series, we will discuss about\u00a0Docker, is an open-source lightweight virtualization tool which runs at top of Operating System level, allowing users to create, run and deploy applications, encapsulated into small containers. Install Docker and Learn Basic Container Manipulation \u2013 Part 1 This type of Linux containers are proven to be fast, portable &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/17\/install-docker-and-learn-basic-container-manipulation-in-centos-and-rhel-7-6\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Install Docker and Learn Basic Container Manipulation in CentOS and RHEL 7\/6&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11798","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11798"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11798\/revisions"}],"predecessor-version":[{"id":11799,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11798\/revisions\/11799"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}