Skip to content

Instantly share code, notes, and snippets.

@tae898
Last active November 28, 2021 15:00
Show Gist options
  • Save tae898/1158659c657daca167c57f00b5d0c4bc to your computer and use it in GitHub Desktop.
Save tae898/1158659c657daca167c57f00b5d0c4bc to your computer and use it in GitHub Desktop.
Dockerfile for running postgres and conceptnet5 locally
# Start from the official postgres image
FROM postgres
# Adding the below environment variables allow you to create a database easily within
# the docker contianer
ENV POSTGRES_USER root
ENV POSTGRES_PASSWORD root
ENV POSTGRES_DB root
# Install the necessary libraries for both postgres and conceptnet
RUN apt update
RUN apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev -y
RUN apt install libreadline-dev libffi-dev curl libbz2-dev libsqlite3-dev git unzip -y
RUN apt install wget libhdf5-dev libmecab-dev mecab-ipadic-utf8 liblzma-dev lzma -y
# Change the default shell to `zsh` since I like it.
RUN apt install watch htop zsh -y
RUN chsh -s $(which zsh)
RUN sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Install python 3.7.12
# Somehow I couldn't just `apt install python3.7`. Here I manually download and compile it.
RUN wget https://www.python.org/ftp/python/3.7.12/Python-3.7.12.tgz
RUN tar -xf Python-3.7.12.tgz
WORKDIR "/Python-3.7.12"
RUN ./configure --enable-optimizations --enable-loadable-sqlite-extensions
RUN make -j$(nproc)
RUN make install
RUN apt install python3-pip python3-dev -y
# Install conceptnet
WORKDIR "/"
RUN git clone https://github.com/commonsense/conceptnet5.git
WORKDIR "/conceptnet5"
# modify `build.sh` in place to speed up processing
RUN sed -i -e 's/-j 2/-j$(nproc) /g' build.sh
RUN pip3 install --upgrade pip
RUN pip3 install wheel
RUN pip3 install -e '.[vectors]'
CMD [ "postgres" ]
@tae898
Copy link
Author

tae898 commented Nov 27, 2021

A big part of the instruction below is copied from here.

You don't have to build the docker image again, since I've already pushed to docker hub.

Here is how to get things done:

  1. Pull the image and run it in detached mode by running

    docker run --name conceptnet5 --network host -d tae898/conceptnet5

    The docker container with the name conceptnet5 container will be running now.

  2. Open up zsh (or bash, whatever you prefer) in the container by running

    docker exec -it conceptnet5 zsh
  3. Create a PostgreSQL database named conceptnet5 by running

    createdb conceptnet5
  4. Start the build by running

    ./build.sh

    This will take a long time since it has to download all the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment