Enabing Shiny Server with Docker Swarm: no replication

Hi, I’m having difficulty with creating replicas of a docker image containing Shiny server in Docker swarm mode.

I create a docker service but no replicas are created:

$ docker stack deploy -c docker-compose_v3.yml docker-compose_v3
$ docker service ls

ID                  NAME                            MODE                REPLICAS            IMAGE                                               PORTS
dn2umli2xce8        docker-compose_v3_dataservice   replicated          0/5                 
sustainableos/shiny:proj_r362_ub1804_shiny_v3   *:80->80/tcp, *:8017->3838/tcp

I can however run a single container of the docker image: When I run the docker image (as follows) a single docker container is created and I can see the Shiny app at the specified port in the browser:

docker run --name shiny_proj_v3 -dit -v '/home/shiny/webapps:/home/shiny/webapps' -v '/gis:/gis' -p 8021:3838 sustainableos/shiny:proj_r362_ub1804_shiny_v3

I’m unclear if the issue with Docker Swarm appears to be related to how I specify commands in the dockerfile. Note that I include /bin/bash in the dockerfile so that the docker container remains open. If I don’t include /bin/bash the container immediately closes.

Key elements of Dockerfile:

#Install Shiny server
 RUN wget -c https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny-server-1.5.14.948-amd64.deb && \
gdebi -n shiny-server-1.5.14.948-amd64.deb 

# Config Shiny server
RUN sed -i -e 's+srv/shiny-server+home/shiny/webapps/proj+g' /etc/shiny-server/shiny-server.conf 

# Permissions to allow shiny server to be run by shiny user (or otherwise run by root)
RUN cd /opt/shiny-server && \
    chown -R shiny:shiny-app . && \
    cd /opt/shiny-server/ext/node/bin && \
    chown shiny:shiny-app shiny-server && \
    cd /var/lib/shiny-server && \
   chown -R shiny:shiny-app .

WORKDIR /home/shiny

#USER shiny

EXPOSE 3838

#CMD ["R", "-e", "shiny::runApp('/home/shiny/webapps/proj')"]

COPY start_script.sh start_script.sh
RUN chmod +x start_script.sh
CMD ./start_script.sh

The start_script.sh script:

  #!/bin/bash
  exec shiny-server &
  /bin/bash

The docker-compose_v3.yml file:

version: "3.8"
services:
  dataservice:
    image: sustainableos/shiny:proj_r362_ub1804_shiny_v3
    deploy:
      replicas: 5
      restart_policy:
        condition: on-failure
    ports:
      - "8017:3838"
      - "80:80"
    volumes:
      - /home/shiny/webapps/proj:/home/shiny/webapps/proj

Thanks for any suggestions.

$ docker --version
Docker version 19.03.11, build 42e35e61f3
Linux Mint 19.3 (Ubuntu 18.04)

The output of docker stack ps docker-compose_v3 --no-trunc usualy provides insights about the scheduling situation.

$docker stack ps docker-compose_v3 --no-trunc 

indicates that the replicas are starting and then shutting down.

odj137fk53bq         \_ docker-compose_v3_dataservice.5   sustainableos/shiny:proj_r362_ub1804_shiny_v3   desktop_rc          Shutdown            Failed 6 seconds ago               "task: non-zero exit (1)"   
ypx9rj5ytbk0         \_ docker-compose_v3_dataservice.5   sustainableos/shiny:proj_r362_ub1804_shiny_v3   desktop_rc          Shutdown            Failed 15 seconds ago              "task: non-zero exit (1)"   
wz7x6yptczdv         \_ docker-compose_v3_dataservice.5   sustainableos/shiny:proj_r362_ub1804_shiny_v3   desktop_rc          Shutdown            Failed 25 seconds ago              "task: non-zero exit (1)"   
ohoe9bgcd2lg         \_ docker-compose_v3_dataservice.5   sustainableos/shiny:proj_r362_ub1804_shiny_v3   desktop_rc          Shutdown            Failed 37 seconds ago              "task: non-zero exit (1)"  


$ docker service logs docker-compose_v3_dataservice 

mentions a TERM environment variable is not set
docker-compose_v3_dataservice.4.qqujukj7dak5@desktop_rc | TERM environment variable not set.

I also tried adding ‘top’ to the start_script.sh to ensure there is a running process, but the replicas shut down.

Actualy your docker run and docker-compose stack are not entirely comparible. Can you retry your 'docker runcommand with thetiin your-dti` option?

This should be an equivalent of your -dit options:

services:
  dataservice:
    ..
    tty: true
    stdin_open: true

The solution I’ve found is that I need to directly include the shiny-server command in the dockerfile:

WORKDIR /home/shiny
USER shiny
EXPOSE 3838    
CMD ["shiny-server"]

I commented out the section on the start_script.sh

#COPY start_script.sh start_script.sh
#RUN chmod a+x start_script.sh
#CMD ./start_script.sh

This enables shiny-server if running a single docker container and also using docker swarm.