Code Monkey home page Code Monkey logo

docker_postgresql_withinvirtualboxubuntu's Introduction

docker_postgresql_withinVirtualboxUbuntu

How to setup postgresql within a docker container (in virtualbox/ubuntu) and use it from within a spring boot application (I'm not using the official postgresql docker image).

Setup

  1. download and install virtualbox 5.2
  2. download an ISO image of ubuntu 16.04
  3. create a vm in virtualbox based on that ubuntu 16.04 iso
  4. within virtualbox/ubuntu, install jdk8 : sudo apt-get install openjdk-8-jdk
  5. within virtualbox/ubuntu, create JAVA_HOME environment variable and add it to the PATH :
        - export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
        - export PATH=$PATH:$JAVA_HOME/bin
  6. within virtualbox/ubuntu, install docker : I personnally followed the docker.com tutorial https://docs.docker.com/engine/install/ubuntu/
  7. within virtualbox/ubuntu, start a container that runs postgresql : sameersbn/postgresql:12-20200524 (this is not the official image but it does the job), run :sudo docker run --name postgresql -itd --restart always --publish 5432:5432 --volume postgresql:/var/lib/postgresql --env 'PG_TRUST_LOCALNET=true' --env 'PG_PASSWORD=postgres' --env 'DB_USER=thollem' --env 'DB_PASS=thollem' --env 'DB_NAME=mydatabase' sameersbn/postgresql:12-20200524 -c listen_addresses='*'
  8. within virtualbox/ubuntu, run the spring boot client to store data in that postgresql database : mvn spring-boot:run
  9. within virtualbox/ubuntu, to see the content in the postgresql database you can :
        (a)rerun the application with 'mvn spring-boot:run' again
        (b)use psql
        (c)use dbeaver (I personnally use that)
    alt text


bonus : access postgresql from the guest machine.
1) allow communication between guest and virtual machine : https://2buntu.com/articles/1513/accessing-your-virtualbox-guest-from-your-host-os/
2) edit the application.properties file : change spring.datasource.url value :
    from spring.datasource.url=jdbc:postgresql://localhost:5432/postgres to spring.datasource.url=jdbc:postgresql://192.168.99.101:5432/postgres


some troubleshoot commands :
- java -version
- sudo service postgresql stop
- sudo docker stop postgresql
- sudo docker rm postgresql

docker_postgresql_withinvirtualboxubuntu's People

Contributors

thomascolomba avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.