I'm new to docker. I need to create a docker image with python, postgresql and redis. I know usually this is not a good practice, since most of the time I should have 3 images and put them together with docker compose. But my case is a little bit special, I need to run my TeamCity build step in a docker wrapper. Seems like you can only specify one docker image for a docker wrapper. So I end up creating this Dockerfile with everything I need.
FROM python:3.8
# install redis
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B && \
apt-get update && \
apt-get install -y redis
# install postgresql
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
apt-get update && \
apt-get install -y postgresql-12 postgresql-contrib-12
# set up postgresql
USER postgres
RUN /etc/init.d/postgresql start && \
psql --command "CREATE USER test_user WITH PASSWORD '123456';" && \
psql --command "CREATE DATABASE test_db WITH OWNER = test_user;"
# start postgresql and redis when container is started
ENTRYPOINT [ "/bin/sh", "-c", "/etc/init.d/postgresql restart && /etc/init.d/redis restart" ]
The image is built successfully. However, when I try to run the image, nothing happens. I think something is wrong with the ENTRYPOINT statement. I googled around and tried a few things, nothing works.
CodePudding user response:
I assume, that the docker container simply exited and that is expected.
The container stays running as long the start up process stays running.
When you restart a service, the init process starts the services in background and the init process simply exits.
Sine the init process exits so does the container, try adding a process that stays running.
E.g
ENTRYPOINT /etc/init.d/postgresql restart && /etc/init.d/redis restart && tail -f /dev/null