April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

dockert centos

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.

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.

In this tutorial, We’ll learn how to install Docker on CentOS-7.

##Requirements

CentOS-7 64-bit configured with static IP address. Kernel version must be 3.10 at minimum.

##Installing Docker

It is recommended to update your system before installing docker.

To update the system, Run:

sudo yum -y update

Docker package is not available in CentOS-7 repository. So you need to create repo for docker.

You can create docker repo by creating docker.repo file inside /etc/yum.repos.d/ directory.

sudo nano /etc/yum.repos.d/docker.repo

Add the following line:


[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

After creating docker repo, run the following command to install docker.

sudo yum install docker-engine

Once docker has been installed, it is recommended to start docker service and set docker service to start at boot.

You can do this by running the following command:

sudo systemctl start docker.service sudo systemctl enable docker.service

You can check the status of Docker by running the following command:

sudo systemctl status docker.service

Finally, you can verify that the latest version of docker is installed with the following command

sudo docker version

You can see the output some thing like this:

Client:
 Version:      1.10.0
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   590d5108
 Built:        Thu Feb  4 18:36:33 2016
 OS/Arch:      linux/amd64

Server:
Version: 1.10.0
API version: 1.22
Go version: go1.5.3
Git commit: 590d5108
Built: Thu Feb 4 18:36:33 2016
OS/Arch: linux/amd64

##Working With Docker

###Downloading a Docker Container

Let’s 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.

sudo docker pull centos

You can see the output some thing like this:

Using default tag: latest
latest: Pulling from library/centos

a3ed95caeb02: Pull complete
196355c4b639: Pull complete
Digest: sha256:381f21e4c7b3724c6f420b2bcfa6e13e47ed155192869a2a04fa10f944c78476
Status: Downloaded newer image for centos:latest

###Running a Docker Container

Now, You just run one command to setup a basic CentOS container with a bash shell.

To run a command in new container, Run:

sudo docker run -i -t centos /bin/bash

Note: -i flag attaches stdin and stdout and -t flag allocates a tty.

That’s it. Now you’re using a bash shell inside of a centos docker container.

There are many containers already available on docker website. You can found any container through a search. For example to search centos container, Run:

sudo docker search centos

You can see the output some thing like this:

NAME                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                          The official build of CentOS.                   2079      [OK]       
jdeathe/centos-ssh              CentOS-6 6.7 x86_64 / CentOS-7 7.2.1511 x8...   19                   [OK]
jdeathe/centos-ssh-apache-php   CentOS-6 6.7 x86_64 / Apache / PHP / PHP M...   14                   [OK]
million12/centos-supervisor     Base CentOS-7 with supervisord launcher, h...   10                   [OK]
blalor/centos                   Bare-bones base CentOS 6.5 image                8                    [OK]
nimmis/java-centos              This is docker images of CentOS 7 with dif...   8                    [OK]
torusware/speedus-centos        Always updated official CentOS docker imag...   7                    [OK]
centos/mariadb55-centos7                                                        3                    [OK]
nickistre/centos-lamp           LAMP on centos setup                            3                    [OK]
nathonfowlie/centos-jre         Latest CentOS image with the JRE pre-insta...   3                    [OK]
consol/sakuli-centos-xfce       Sakuli end-2-end testing and monitoring co...   2                    [OK]
timhughes/centos                Centos with systemd installed and running       1                    [OK]
darksheer/centos                Base Centos Image -- Updated hourly             1                    [OK]
softvisio/centos                Centos                                          1                    [OK]
lighthopper/orientdb-centos     A Dockerfile for creating an OrientDB imag...   1                    [OK]
yajo/centos-epel                CentOS with EPEL and fully updated              1                    [OK]
grayzone/centos                 auto build for centos.                          0                    [OK]
ustclug/centos                   USTC centos                                    0                    [OK]
januswel/centos                 yum update-ed CentOS image                      0                    [OK]
dmglab/centos                   CentOS with some extras - This is for the ...   0                    [OK]
jsmigel/centos-epel             Docker base image of CentOS w/ EPEL installed   0                    [OK]
grossws/centos                  CentOS 6 and 7 base images with gosu and l...   0                    [OK]
labengine/centos                Centos image base                               0                    [OK]
lighthopper/openjdk-centos      A Dockerfile for creating an OpenJDK image...   0                    [OK]
blacklabelops/centos            CentOS Base Image! Built and Updates Daily!     0                    [OK]

You can also list all available images on your system using the following command:

sudo docker images

You can see the output some thing like this:

REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
firefox-instance            latest              8e61bff07fa0        3 weeks ago         354.6 MB
centos                      latest              d0e7f81ca65c        4 weeks ago         196.6 MB
debian                      latest              f50f9524513f        4 weeks ago         125.1 MB
apache/ubuntu               latest              196655130bc9        4 weeks ago         224.1 MB
apache-instance             latest              7da78270c5f7        4 weeks ago         224.1 MB
apache-instance             ubuntu              7da78270c5f7        4 weeks ago         224.1 MB
hitjethva/apache-instance   ubuntu              7da78270c5f7        4 weeks ago         224.1 MB

##Docker basic command lines

Let’s start with seeing all available commands docker have.

You can list all available docker command by running the following command:

sudo docker

You should see the following output:

Commands:
``` language-bash
    attach    Attach to a running container
    build     Build an image from a Dockerfile
    commit    Create a new image from a container's changes
    cp        Copy files/folders between a container and the local filesystem
    create    Create a new container
    diff      Inspect changes on a container's filesystem
    events    Get real time events from the server
    exec      Run a command in a running container
    export    Export a container's filesystem as a tar archive
    history   Show the history of an image
    images    List images
    import    Import the contents from a tarball to create a filesystem image
    info      Display system-wide information
    inspect   Return low-level information on a container or image
    kill      Kill a running container
    load      Load an image from a tar archive or STDIN
    login     Register or log in to a Docker registry
    logout    Log out from a Docker registry
    logs      Fetch the logs of a container
    network   Manage Docker networks
    pause     Pause all processes within a container
    port      List port mappings or a specific mapping for the CONTAINER
    ps        List containers
    pull      Pull an image or a repository from a registry
    push      Push an image or a repository to a registry
    rename    Rename a container
    restart   Restart a container
    rm        Remove one or more containers
    rmi       Remove one or more images
    run       Run a command in a new container
    save      Save an image(s) to a tar archive
    search    Search the Docker Hub for images
    start     Start one or more stopped containers
    stats     Display a live stream of container(s) resource usage statistics
    stop      Stop a running container
    tag       Tag an image into a repository
    top       Display the running processes of a container
    unpause   Unpause all processes within a container
    update    Update resources of one or more containers
    version   Show the Docker version information
    volume    Manage Docker volumes
    wait      Block until a container stops, then print its exit code

Run ‘docker COMMAND –help’ for more information on a command.


To check system-wide information on docker, run:

`sudo docker info`

You should see the following output:

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


You can use the following command to list all running containers:

`sudo docker ps`

You can see the running container in following image:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 534544f2e924 centos “/bin/bash” 30 seconds ago Up 29 seconds boring_hamilton “`

You can also list both running and non-running containers by running the following command:

sudo docker ps -a

Sometimes container stops due to its process ending or you stopping it explicitly. In this situation you can run container again with container ID.

sudo docker run "container ID"

You can also stop a running container by running the following command:

sudo docker stop "container ID"

Note: You can find container ID using sudo docker ps command.

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.

sudo docker commit "container ID" image_name

This command turns your container to an image. You can roll back when your container you need.

If you want to attach into a running container, Docker allows you to interaction with running containers using the attach command.

You can use attach command with the container ID..

sudo docker attach "container ID"

##Stop and Delete all Containers and Images

To stop all running containers, Run:

sudo docker stop $(docker ps -a -q)

To delete all existing containers, Run:

sudo docker rm $(docker ps -a -q)

To delete all existing images, Run:

sudo docker rmi $(docker images -q -a)

##Conclusion

Congratulations! You now have a centos server with a Docker platform for your application development environment.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>