{"id":7260,"date":"2018-03-13T17:28:50","date_gmt":"2018-03-13T09:28:50","guid":{"rendered":"http:\/\/rmohan.com\/?p=7260"},"modified":"2018-03-13T17:29:38","modified_gmt":"2018-03-13T09:29:38","slug":"dockert-centos","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7260","title":{"rendered":"dockert centos"},"content":{"rendered":"<p>Docker is an open-source tool that automates the deployment of applications inside software containers by providing an additional layer of abstraction of operating system level virtualization on Linux. Docker makes it easier to create, deploy and run applications by using containers. Containers allow a developer to package up an application with all of the libraries and dependencies, and ship it all out as one package. Docker is same as virtual machine, rather than creating a whole virtual operating system. Docker allows applications to use the same Linux kernel as the system that they are running on. This gives a significant performance boost and reduces the size of the application.<\/p>\n<p>Docker is preferred by many system admins and developers to maximize their creativity in an App production environment. For system admins, Docker gives flexibility and reduces the number of systems needed because of its small footprint and lower overhead.<\/p>\n<p>In this tutorial, We&#8217;ll learn how to install Docker on CentOS-7.<\/p>\n<p>##Requirements<\/p>\n<p>CentOS-7 64-bit configured with static IP address. Kernel version must be 3.10 at minimum.<\/p>\n<p>##Installing Docker<\/p>\n<p>It is recommended to update your system before installing docker.<\/p>\n<p>To update the system, Run:<\/p>\n<p><code>sudo yum -y update<\/code><\/p>\n<p>Docker package is not available in CentOS-7 repository. So you need to create repo for docker.<\/p>\n<p>You can create docker repo by creating docker.repo file inside \/etc\/yum.repos.d\/ directory.<\/p>\n<p><code>sudo nano \/etc\/yum.repos.d\/docker.repo<\/code><\/p>\n<p>Add the following line:<\/p>\n<pre><code>\r\n[dockerrepo]\r\nname=Docker Repository\r\nbaseurl=https:\/\/yum.dockerproject.org\/repo\/main\/centos\/7\r\nenabled=1\r\ngpgcheck=1\r\ngpgkey=https:\/\/yum.dockerproject.org\/gpg\r\n<\/code><\/pre>\n<p>After creating docker repo, run the following command to install docker.<\/p>\n<p><code>sudo yum install docker-engine<\/code><\/p>\n<p>Once docker has been installed, it is recommended to start docker service and set docker service to start at boot.<\/p>\n<p>You can do this by running the following command:<\/p>\n<p><code>sudo systemctl start docker.service<\/code> <code>sudo systemctl enable docker.service<\/code><\/p>\n<p>You can check the status of Docker by running the following command:<\/p>\n<p><code>sudo systemctl status docker.service<\/code><\/p>\n<p>Finally, you can verify that the latest version of docker is installed with the following command<\/p>\n<p><code>sudo docker version<\/code><\/p>\n<p>You can see the output some thing like this:<\/p>\n<pre><code>Client:\r\n Version:      1.10.0\r\n API version:  1.22\r\n Go version:   go1.5.3\r\n Git commit:   590d5108\r\n Built:        Thu Feb  4 18:36:33 2016\r\n OS\/Arch:      linux\/amd64<\/code><\/pre>\n<p><code>Server:<br \/>\nVersion:      1.10.0<br \/>\nAPI version:  1.22<br \/>\nGo version:   go1.5.3<br \/>\nGit commit:   590d5108<br \/>\nBuilt:        Thu Feb  4 18:36:33 2016<br \/>\nOS\/Arch:      linux\/amd64<br \/>\n<\/code><\/p>\n<p>##Working With Docker<\/p>\n<p>###Downloading a Docker Container<\/p>\n<p>Let\u2019s start using docker. You will need to have an image present on your host machine where the containers will exist. You can download the CentOS docker image by running the following command.<\/p>\n<p><code>sudo docker pull centos<\/code><\/p>\n<p>You can see the output some thing like this:<\/p>\n<pre><code>Using default tag: latest\r\nlatest: Pulling from library\/centos<\/code><\/pre>\n<p><code>a3ed95caeb02: Pull complete<br \/>\n196355c4b639: Pull complete<br \/>\nDigest: sha256:381f21e4c7b3724c6f420b2bcfa6e13e47ed155192869a2a04fa10f944c78476<br \/>\nStatus: Downloaded newer image for centos:latest<br \/>\n<\/code><\/p>\n<p>###Running a Docker Container<\/p>\n<p>Now, You just run one command to setup a basic CentOS container with a bash shell.<\/p>\n<p>To run a command in new container, Run:<\/p>\n<p><code>sudo docker run -i -t centos \/bin\/bash<\/code><\/p>\n<p>Note: -i flag attaches stdin and stdout and -t flag allocates a tty.<\/p>\n<p>That&#8217;s it. Now you&#8217;re using a bash shell inside of a centos docker container.<\/p>\n<p>There are many containers already available on docker website. You can found any container through a search. For example to search centos container, Run:<\/p>\n<p><code>sudo docker search centos<\/code><\/p>\n<p>You can see the output some thing like this:<\/p>\n<pre><code>NAME                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED\r\ncentos                          The official build of CentOS.                   2079      [OK]       \r\njdeathe\/centos-ssh              CentOS-6 6.7 x86_64 \/ CentOS-7 7.2.1511 x8...   19                   [OK]\r\njdeathe\/centos-ssh-apache-php   CentOS-6 6.7 x86_64 \/ Apache \/ PHP \/ PHP M...   14                   [OK]\r\nmillion12\/centos-supervisor     Base CentOS-7 with supervisord launcher, h...   10                   [OK]\r\nblalor\/centos                   Bare-bones base CentOS 6.5 image                8                    [OK]\r\nnimmis\/java-centos              This is docker images of CentOS 7 with dif...   8                    [OK]\r\ntorusware\/speedus-centos        Always updated official CentOS docker imag...   7                    [OK]\r\ncentos\/mariadb55-centos7                                                        3                    [OK]\r\nnickistre\/centos-lamp           LAMP on centos setup                            3                    [OK]\r\nnathonfowlie\/centos-jre         Latest CentOS image with the JRE pre-insta...   3                    [OK]\r\nconsol\/sakuli-centos-xfce       Sakuli end-2-end testing and monitoring co...   2                    [OK]\r\ntimhughes\/centos                Centos with systemd installed and running       1                    [OK]\r\ndarksheer\/centos                Base Centos Image -- Updated hourly             1                    [OK]\r\nsoftvisio\/centos                Centos                                          1                    [OK]\r\nlighthopper\/orientdb-centos     A Dockerfile for creating an OrientDB imag...   1                    [OK]\r\nyajo\/centos-epel                CentOS with EPEL and fully updated              1                    [OK]\r\ngrayzone\/centos                 auto build for centos.                          0                    [OK]\r\nustclug\/centos                   USTC centos                                    0                    [OK]\r\njanuswel\/centos                 yum update-ed CentOS image                      0                    [OK]\r\ndmglab\/centos                   CentOS with some extras - This is for the ...   0                    [OK]\r\njsmigel\/centos-epel             Docker base image of CentOS w\/ EPEL installed   0                    [OK]\r\ngrossws\/centos                  CentOS 6 and 7 base images with gosu and l...   0                    [OK]\r\nlabengine\/centos                Centos image base                               0                    [OK]\r\nlighthopper\/openjdk-centos      A Dockerfile for creating an OpenJDK image...   0                    [OK]\r\nblacklabelops\/centos            CentOS Base Image! Built and Updates Daily!     0                    [OK]\r\n<\/code><\/pre>\n<p>You can also list all available images on your system using the following command:<\/p>\n<p><code>sudo docker images<\/code><\/p>\n<p>You can see the output some thing like this:<\/p>\n<pre><code>REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE\r\nfirefox-instance            latest              8e61bff07fa0        3 weeks ago         354.6 MB\r\ncentos                      latest              d0e7f81ca65c        4 weeks ago         196.6 MB\r\ndebian                      latest              f50f9524513f        4 weeks ago         125.1 MB\r\napache\/ubuntu               latest              196655130bc9        4 weeks ago         224.1 MB\r\napache-instance             latest              7da78270c5f7        4 weeks ago         224.1 MB\r\napache-instance             ubuntu              7da78270c5f7        4 weeks ago         224.1 MB\r\nhitjethva\/apache-instance   ubuntu              7da78270c5f7        4 weeks ago         224.1 MB\r\n<\/code><\/pre>\n<p>##Docker basic command lines<\/p>\n<p>Let&#8217;s start with seeing all available commands docker have.<\/p>\n<p>You can list all available docker command by running the following command:<\/p>\n<p><code>sudo docker<\/code><\/p>\n<p>You should see the following output:<\/p>\n<pre><code>Commands:\r\n``` language-bash\r\n    attach    Attach to a running container\r\n    build     Build an image from a Dockerfile\r\n    commit    Create a new image from a container's changes\r\n    cp        Copy files\/folders between a container and the local filesystem\r\n    create    Create a new container\r\n    diff      Inspect changes on a container's filesystem\r\n    events    Get real time events from the server\r\n    exec      Run a command in a running container\r\n    export    Export a container's filesystem as a tar archive\r\n    history   Show the history of an image\r\n    images    List images\r\n    import    Import the contents from a tarball to create a filesystem image\r\n    info      Display system-wide information\r\n    inspect   Return low-level information on a container or image\r\n    kill      Kill a running container\r\n    load      Load an image from a tar archive or STDIN\r\n    login     Register or log in to a Docker registry\r\n    logout    Log out from a Docker registry\r\n    logs      Fetch the logs of a container\r\n    network   Manage Docker networks\r\n    pause     Pause all processes within a container\r\n    port      List port mappings or a specific mapping for the CONTAINER\r\n    ps        List containers\r\n    pull      Pull an image or a repository from a registry\r\n    push      Push an image or a repository to a registry\r\n    rename    Rename a container\r\n    restart   Restart a container\r\n    rm        Remove one or more containers\r\n    rmi       Remove one or more images\r\n    run       Run a command in a new container\r\n    save      Save an image(s) to a tar archive\r\n    search    Search the Docker Hub for images\r\n    start     Start one or more stopped containers\r\n    stats     Display a live stream of container(s) resource usage statistics\r\n    stop      Stop a running container\r\n    tag       Tag an image into a repository\r\n    top       Display the running processes of a container\r\n    unpause   Unpause all processes within a container\r\n    update    Update resources of one or more containers\r\n    version   Show the Docker version information\r\n    volume    Manage Docker volumes\r\n    wait      Block until a container stops, then print its exit code\r\n<\/code><\/pre>\n<p>Run &#8216;docker COMMAND &#8211;help&#8217; for more information on a command.<\/p>\n<pre><code>\r\nTo check system-wide information on docker, run:<\/code><\/pre>\n<p>`sudo docker info`<\/p>\n<pre><code><\/code><\/pre>\n<p><code>You should see the following output:<br \/>\n<\/code><\/p>\n<p>Containers: 6 Running: 0 Paused: 0 Stopped: 6 Images: 22 Server Version: 1.10.0 Storage Driver: aufs Root Dir: \/var\/lib\/docker\/aufs Backing Filesystem: extfs Dirs: 35 Dirperm1 Supported: false Execution Driver: native-0.2 Logging Driver: json-file Plugins: Volume: local Network: bridge null host Kernel Version: 3.13.0-32-generic Operating System: Zorin OS 9 OSType: linux Architecture: x86_64 CPUs: 4 Total Memory: 3.746 GiB Name: Vyom-PC ID: G2NZ:3DDJ:KJFV:HC2E:HR3Y:J4JH:TX2D:EX57:K26Y:3AFH:FGKB:XEIF Username: hitjethva Registry: https:\/\/index.docker.io\/v1\/ WARNING: No swap limit support<\/p>\n<pre><code>\r\nYou can use the following command to list all running containers:<\/code><\/pre>\n<p>`sudo docker ps`<\/p>\n<pre><code><\/code><\/pre>\n<p><code>You can see the running container in following image:<br \/>\n<\/code><\/p>\n<p>CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 534544f2e924 centos &#8220;\/bin\/bash&#8221; 30 seconds ago Up 29 seconds boring_hamilton &#8220;`<\/p>\n<p>You can also list both running and non-running containers by running the following command:<\/p>\n<p><code>sudo docker ps -a<\/code><\/p>\n<p>Sometimes container stops due to its process ending or you stopping it explicitly. In this situation you can run container again with container ID.<\/p>\n<p><code>sudo docker run \"container ID\"<\/code><\/p>\n<p>You can also stop a running container by running the following command:<\/p>\n<p><code>sudo docker stop \"container ID\"<\/code><\/p>\n<p>Note: You can find container ID using <code>sudo docker ps<\/code> command.<\/p>\n<p>If you would like to save the changes you have made with a container, use commit command to save to save it as an image.<\/p>\n<p><code>sudo docker commit \"container ID\" image_name<\/code><\/p>\n<p>This command turns your container to an image. You can roll back when your container you need.<\/p>\n<p>If you want to attach into a running container, Docker allows you to interaction with running containers using the attach command.<\/p>\n<p>You can use attach command with the container ID..<\/p>\n<p><code>sudo docker attach \"container ID\"<\/code><\/p>\n<p>##Stop and Delete all Containers and Images<\/p>\n<p>To stop all running containers, Run:<\/p>\n<p><code>sudo docker stop $(docker ps -a -q)<\/code><\/p>\n<p>To delete all existing containers, Run:<\/p>\n<p><code>sudo docker rm $(docker ps -a -q)<\/code><\/p>\n<p>To delete all existing images, Run:<\/p>\n<p><code>sudo docker rmi $(docker images -q -a)<\/code><\/p>\n<p>##Conclusion<\/p>\n<p>Congratulations! You now have a centos server with a Docker platform for your application development environment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker is an open-source tool that automates the deployment of applications inside software containers by providing an additional layer of abstraction of operating system level virtualization on Linux. Docker makes it easier to create, deploy and run applications by using containers. Containers allow a developer to package up an application with all of the libraries [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7260"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7260"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7260\/revisions"}],"predecessor-version":[{"id":7262,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7260\/revisions\/7262"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}