Tuesday, 27 September 2016

Setup Docker and then Postgres on the Docker Centos6.

Follow the steps one to six under heading Install with yum given in below link to setup and start docker.


Install with yum

  1. Log into your machine as a user with sudo or root privileges.
  2. Make sure your existing yum packages are up-to-date.
    $ sudo yum update
    
  3. Add the yum repo.
    $ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
    [dockerrepo]
    name=Docker Repository
    baseurl=https://yum.dockerproject.org/repo/main/centos/6/
    enabled=1
    gpgcheck=1
    gpgkey=https://yum.dockerproject.org/gpg
    EOF
    
  4. Install the Docker package.
    $ sudo yum install docker-engine
    
  5. Start the Docker daemon.
    $ sudo service docker start
    
  6. Verify docker is installed correctly by running a test image in a container.
    $ sudo docker run hello-world
    Unable to find image 'hello-world:latest' locally
        latest: Pulling from hello-world
        a8219747be10: Pull complete
        91c95931e552: Already exists
        hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
        Digest: sha256:aa03e5d0d5553b4c3473e89c8619cf79df368babd1.7.1cf5daeb82aab55838d
        Status: Downloaded newer image for hello-world:latest
        Hello from Docker.
        This message shows that your installation appears to be working correctly.
    
        To generate this message, Docker took the following steps:
         1. The Docker client contacted the Docker daemon.
         2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
                (Assuming it was not already locally available.)
         3. The Docker daemon created a new container from that image which runs the
                executable that produces the output you are currently reading.
         4. The Docker daemon streamed that output to the Docker client, which sent it
                to your terminal.
    
        To try something more ambitious, you can run an Ubuntu container with:
         $ docker run -it ubuntu bash
    
        For more examples and ideas, visit:
         http://docs.docker.com/userguide/
  7. If you are behind proxy then follow the below link and restart the docker as given below.
  8. https://crondev.com/running-docker-behind-proxy/
For RedHat/CentOS version 6:



Now you are ready to setup PostgreSQL.


Execute following command and it will pull latest version of PostgreSQL and follow link below to start and connect PostgreSQL with docker.

Link is given below.



docker pull postgres




start a postgres instance


$ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres


docker run --name postgres9.5 -e POSTGRES_PASSWORD=postgres -d postgres




Start psql


$ docker run -it --rm --link some-postgres:postgres postgres psql -h postgres -U postgres
psql (9.5.0)
Type "help" for help.

postgres=# SELECT 1;
 ?column? 
----------
        1
(1 row)





docker run -it --rm --link postgres9.5:postgres postgres psql -h postgres -U postgres



Password for user postgres:
psql (9.5.4)
Type "help" for help.

postgres=# select 1;
 ?column?
----------
        1
(1 row)


postgres=# \q





First execute following command to list running docker.

[root@centos6_pri lib]# docker ps -a

It will show you the name of the all docker images avaliable and their status in my case is  "postgres9.5"


To login to Docker

 docker exec -i -t postgres9.5 /bin/bash

No comments:

Post a Comment