How can i start multi service in a Dockerfile without compose

My Target

I want to build an image with Python3 and redis-server

My Action

Usually, we achieve it by writing a docker-compose.yaml with redis service and an app service.
But I have to put them together in a container (or image) for some reasons.

Problems

The repository doesn’t have appropriate image which I need, I have to build it myself.

Below is my Dockerfile

FROM python3.7

WORKDIR /usr/src
RUN wget http://download.redis.io/redis-stable.tar.gz
RUN tar xvzf redis-stable.tar.gz
WORKDIR /usr/src/redis-stable
RUN make install
CMD src/redis-server
WORKDIR /usr/src/redis-stable/src

RUN redis-server & # 启动redis服务

WORKDIR /usr/src/app

ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8

COPY requirements.txt ./
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD uvicorn main:app --log-level info --host 0.0.0.0 --port 8082 --workers 4

not very precise ,but just like that.

Now I can’t start redis-server success.
I have to start it onlt by get into the container and run the start cmd.
I want to start both the redis and app when the container was created.

Any help would be apprecated a lot~~

You can add .sh file with the necessary commands to Dockerfile.

start-app.sh file example:

#!/bin/sh
redis-server --daemonize yes
gunicorn main:app --log-level info --host 0.0.0.0 --port 8082 --workers 4

And Dockerfile will look take:

FROM python3.7
WORKDIR /usr/src
RUN wget http://download.redis.io/redis-stable.tar.gz
RUN tar xvzf redis-stable.tar.gz
WORKDIR /usr/src/redis-stable
RUN make install

WORKDIR /usr/src/app

ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8

COPY requirements.txt ./
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["./start-app.sh"]

Wooo!
That really inspired me!
Thank you very much for your sincere help :slight_smile: