Docker Community Forums

Share and learn in the Docker community.

Problem starting multiple services


(RobF) #1

Hi all, hope you can help! I’m very new to docker / linux based systems so I apologise in advance if my basic knowledge is a bit flaky!

I’m running docker (latest stable version 18.03) on a mac with OSX 10.13.3. The image I’m setting up is to run on a Raspberry Pi 3 running base image of “resin/rpi-raspbian:stretch”

The problem I’m having is getting services to start in the container on run. I’ve looked into CMD / ENTRYPOINT and tried multiple variations from lots of posts (so I havent just taken the easy route and jumped on here) but cannot get them to start automatically.

I actually need three different services to start when the container runs lighttpd / mysql and a custom service written in house. I have tried stripping it back to just get one of the services to start and then take it from there but I cant even get that to work!

I’ve tried running a start up script from command as well as trying to start the individual services from CMD just to get one going but no luck yet.

If I SSH into the container and manually start the services they run no problem so I’m assuming everything they need to work is in the image its just the method to start it automatically on container run that I’m having an issue with.

I expect I’m either misunderstanding the basics of how docker works or getting the start up routine wrong.

Hope you can help and many thanks in advance!

Cheers

Rob


(Garylonbrown) #2

You might peek at:


(David Maze) #3

The standard pattern is to run these in three separate containers. You can use Docker Compose to coordinate launching them. I’d recommend using the standard mysql container over trying to roll your own, not that it’s complicated but that it’s out there and works just fine.


(RobF) #4

Hi, thanks for responding. I had already seen this thread and tried what it said but still cant get the service to start automatically. As I have a number of services to start the script file looked like it would do the job but I cant get it to work for a single service let alone all three. Is it possibly anything to do with the way I’m starting the container?

docker run -d -p 80:80/tcp -p 8000:8000/tcp --name skinbase-cont skinbase-rf

I then get into the container using :
exec -it skinbase-cont /bin/bash

Once I’m in I check if the service(s) are runing using :
service mysql status

… Ive tried the methods in the post for starting all three and each one individually but whenever I check none of them are running. If I manually start them using :
service mysql start

They start up and continue running no problem and I can access my app via a local browser.
Thanks again for your help.
Cheers
Rob


(RobF) #5

Hi David, thanks for posting back, I had read about using separate containers for each service and that was next on my “list of things to learn” however I just wanted to get something “basic” working to get a grip of the basics before moving on to something more advanced.

The problem is I cant even get a single service to start in the container (see my other reply to @garylonbrown). My assumption is I’m doing something fundamentally wrong in the setup / execution of the container so until I can get something basic running (i.e. a single service) I dont want to move on to anything more advanced.

Thanks again for your help.

Rob


(David Maze) #6

A general rule around Docker is that one container usually does one thing; and if you want a container that does more than one thing, you’re totally responsible for all of the machinery that makes it work. I’m guessing you’ll find a multi-container setup easier.

Containers usually don’t run init processes (especially now that Linux distributions seem to have standardized on the incredibly heavyweight systemd, which does so many system-level things that it can’t really be run in a Docker container) and so commands like “service” and “systemctl” and “/etc/init.d/…” tend to just not work.

If you really want to go down this path, supervisord is a popular process manager, but I still think it will be easier (and better form) to split this up into three containers.


(Garylonbrown) #7

Leave off the /tcp from port assignments then try running after. Before doing anything else, check the docker logs. Use docker ps to get the container ID then do docker logs [containerid] and see if you get any clues there as to what might be failing if anything. If still a problem, can you post your Dockerfile?


(Danielpops) #8

A pattern that might work for you is the following:

Make your entry point a shell script. That she’ll script will do three things:

  1. Start MySQL service
  2. Start lighttpd
  3. Whatever business logic is needed for initializing and starting your service

So run.sh might look like

#!/bin/bash
service mysql start
service lighttpd start
python server.py # this is your servIce that runs indefinitely

Now, as others have said, you may want to eventually move to a model with separate containers and using docker compose for orchestration, but this should let you at least get something up and running in the way that’s comfortable for you :slight_smile:


(RobF) #9

Hi all, thanks again for taking the time to assist!

As I said, I get that using multiple containers may be the best option long term but I cant get just one service to spin up and keep the container “active”.

My docker file is below :

USE OFFICIAL RESIN RASPBIAN IMAGE

FROM resin/rpi-raspbian:stretch

INSTALL PACKAGES

RUN apt-get update &&
apt-get install -yq --no-install-recommends
apt-utils
lighttpd
pigpio
chromium-browser
mysql-server
mysql-client
php7.0-cgi
php7.0-fpm
php7.0-mysql
php7.0-curl
php7.0-gd
php7.0-intl
php-pear
php-imagick
php7.0-imap
php7.0-mcrypt
php-memcache
php7.0-pspell
php7.0-recode
php7.0-sqlite3
php7.0-tidy
php7.0-xmlrpc
php7.0-xsl
php7.0-mbstring
php-gettext
php7.0
libwebsockets-dev
nano

Defines our working directory in container

WORKDIR ./

This will copy all files in our root to the working directory in the container

COPY . ./

RUN sudo lighttpd-enable-mod fastcgi &&
sudo lighttpd-enable-mod fastcgi-php &&
sudo chmod +x /etc/skinbase/skinbasesvc &&
sudo chmod 777 /tmp/ &&
sudo chmod 777 /start.sh &&
sudo service mysql start &&
sudo bash /etc/skinbase/mysql_setup.sh &&
sudo mysql -u root -e “CREATE DATABASE skinbase” &&
sudo mysql -u root skinbase < /tmp/skinbase.sql

#Clean up packages and remove install files.
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

Enable systemd init system in container

ENV INITSYSTEM ON

#EXPOSE PORT 80 / 8000 TO ACCESS SITE
EXPOSE 80
EXPOSE 8000

CMD ["/bin/bash","./start.sh"]

The start.sh file contains :

#!/bin/bash
echo “Starting services” &&
sudo service lighttpd start &&
sudo service mysql start &&
sudo service skinbasesvc start &&
echo “Start complete”

If I build / run this container and look at the logs all I get is :

Systemd init system enabled.

Log into the container using : “docker exec -it skinbase-cont /bin/bash” and none of the services are running. If I strip back start.sh to just once service (e.g. lighttpd) again, when I log in nothing is running.

TIA

Rob


(RobF) #10

Oh, one other thing, since I updated to the latest version of docker I keep seeing the warnings below when building the image.

Unknown QEMU_IFLA_INFO_KIND ipip
Unknown QEMU_IFLA_INFO_KIND ip6tnl
Unknown QEMU_IFLA_INFO_KIND ipip
Unknown QEMU_IFLA_INFO_KIND ip6tnl
Unknown QEMU_IFLA_INFO_KIND ipip
Unknown QEMU_IFLA_INFO_KIND ip6tnl
Unknown QEMU_IFLA_INFO_KIND ipip
Unknown QEMU_IFLA_INFO_KIND ip6tnl
Unknown QEMU_IFLA_INFO_KIND ipip
Unknown QEMU_IFLA_INFO_KIND ip6tnl
Unknown QEMU_IFLA_INFO_KIND ipip
Unknown QEMU_IFLA_INFO_KIND ip6tnl
Unknown QEMU_IFLA_INFO_KIND ipip
Unknown QEMU_IFLA_INFO_KIND ip6tnl

Not sure what they are, I have searched about them but the technical explanations go way over my head! :wink: However could this be part of the problem?

Cheers,