How to run background applications using Docker?

Asked

Viewed 244 times

1

I’m trying to run my Python application inside a container, only I need to install a proxy dependency that I use: Luminati, the problem is that apparently luminati is not running in the background after I initialize the container.

I tried to run it this way:

docker run -it test_app:latest

When rotating a ps ax luminati application is not rotating!

Docker-Compose.yml

version: '3'

services:
  app:
    build: .
    volumes:
      - .:/shared
    networks:
      - vnet-front

networks:
   vnet-front:
     driver: bridge

Dockerfile

FROM python:3.6-alpine AS build-ev

RUN apk add nodejs
RUN apk add npm
RUN npm install -g @luminati-io/luminati-proxy --unsafe-perm
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN luminati --config luminati.json
ENTRYPOINT ["python", "test.py"]
  • I want the container to run the command luminati --config luminati.json and also my entrypoint, the problem is that when I run in interactive mode the processes are not running.

  • I’ll test just a moment.

  • Anyway, when I give a ps Ax: bash-4.4# ps ax
PID USER TIME COMMAND
 1 root 0:00 /bin/bash
 8 root 0:00 ps ax

  • Okay, thank you!!!

1 answer

1


So you can start your application at the time the container is called, rather than using the RUN you use the CMD:

Dockerfile altered:

FROM python:3.6-alpine AS build-ev

RUN apk add nodejs
RUN apk add npm
RUN npm install -g @luminati-io/luminati-proxy --unsafe-perm
RUN mkdir /app
WORKDIR /app
COPY . /app

CMD luminati --config luminati.json && python test.py

So, at the moment startar your image (something like):

docker run -d -p 22999:80 test_app:latest

The application (luminati) will be executed and your test.py also.

  • I’ll test and warn you! Thank you.

  • It worked perfectly, can you tell me why it didn’t work before? Is it necessary to map the port? I could run here without needing to map.

  • I believe it was because I was using the RUN to start the luminati, it is used during the process of build image, and not as you were doing, calling your application. Take a look at the doc, explains that well.

  • Ah, my bad! Thanks friend.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.