How to create a docker image with Ruby and Postgresql 9.5

Hi everyone,

I would love to use docker pipeline but my Ruby on Rails app needs Postgresql 9.5. When using 


FROM ruby:2.2.1
RUN apt-get update \
  && apt-get install -y postgresql postgresql-contrib \
  && apt-get install sudo \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*


I'm getting the 9.4 version and  adding apt-get to the 9.5 apt-get install -y gives me an error that the package is not found. I've read that adding packages to apt get can be done as 

RUN sudo sh -c 'echo "deb `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
RUN wget -q -O - | sudo apt-key add -


but this doesn't work in the dockerfile


Please help



1 answer

Hi PJ,

Try this and let me know if it works?

FROM ruby:2.2.1 
RUN sh -c 'echo "deb precise-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' \
  && wget -q -O - | apt-key add - \
  && apt-get update \
  && apt-get install -y postgresql-9.5 postgresql-contrib-9.5 \
  && apt-get install sudo \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# This Dockerfile doesn't need to have an entrypoint and a command
# as Bitbucket Pipelines will overwrite it with a bash script.

You are already root so you don't need to run commands with sudo. And I found a different way to update the sources from the Docker documentation.



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Thursday in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder :  #!/bin/bash source "$(dirname "$0")/" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

220 views 0 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you