20210810 TIL
docker compose를 이용해서 r-shiny app을 구동하는 proxy 서버를 띄우는 작업을 해야하는데 r로 이런걸 하는건 처음이라 좀 오래 걸렸다. 반나절을 다 써버렸네... 시간 아깝구로.. 그리고 공식 홈페이지 설명은 개떡같다. 도커고 도커 컴포즈고 네트워크고 잘 모르는 사람이 했다면 시간 엄청 잡아먹었을듯... 역시 프레임워크 선정은 사람이 많이 쓰는걸 해야 에러 잡기가 쉽다. 레퍼런스가 많으니... 아무튼 감사의 의미와 잊지 않겠다는 의미로 아래에 해당 내용을 정리한 것을 붙여넣었다.
How to use
Download a template:
# Download a template
git clone git@github.com:kassambara/shinyproxy-config.git
cd shinyproxy-config/docker-compose-example
Template folder structure:
docker-compose-example
├── docker-compose.yml
├── shinyapps
│ └── euler-docker
│ ├── Dockerfile
│ ├── Rprofile.site
│ └── euler
│ ├── server.R
│ └── ui.R
└── shinyproxy
├── Dockerfile
└── application.yml
Content of the docker-compose.yml:
version: "3.6"
services:
shinyproxy:
image: datanovia/shinyproxy
container_name: dnv_shinyproxy
restart: on-failure
build: ./shinyproxy
networks:
- dnv-net
ports:
- 8080:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./shinyproxy-logs/server:/log
- ./shinyproxy-logs/container:/container-logs
- ./shinyproxy/application.yml:/opt/shinyproxy/application.yml
euler:
image: euler-docker
container_name: dnv_euler
build: ./shinyapps/euler-docker
networks:
- dnv-net
networks:
dnv-net:
name: dnv-net
Content of the ShinyProxy application.yaml:
proxy:
title: ShinyProxy
port: 8080
authentication: simple
admin-groups: admins
users:
- name: jack
password: password
groups: admins
- name: jeff
password: password
docker:
internal-networking: true
container-network: dnv-net
# change this route to your work directory, use absolute path
# work-directory: /Users/kassambara/Documents/shinyproxy-docker-compose-example
specs:
- id: 01_hello
display-name: Hello Application
description: Application which demonstrates the basics of a Shiny app
container-cmd: ["R", "-e", "shinyproxy::run_01_hello()"]
container-image: openanalytics/shinyproxy-demo
container-network: "${proxy.docker.container-network}"
# container-volumes: ["${proxy.work-directory}/apps:/apps"]
- id: euler
display-name: Euler's number
container-cmd: ["R", "-e", "shiny::runApp('/root/euler')"]
container-image: euler-docker
container-network: "${proxy.docker.container-network}"
logging:
file:
/log/shinyproxy.log
Docker uses networks
to enable communication between containers. For ShinyProxy to communicate properly with the Shiny App, the network specified in docker-compose.yml
must be the same as the same as that listed in application.yml
. (Tip, if you’re using a docker-compose file to launch the app, don’t set up the docker network manually, see here for why).
Each container listed in services
: is named in container_name, with the Dockerfile being pointed to via. the context
and Dockerfile
variables. If the container was terminated with an error code, the restart
line instructs Docker what action is to be taken . The networks
variables lists the Docker network that the container has access to.
The network used by all applications in this docker-compose
must match the network specified in the ShinyProxy application.yml
.
Building and running
# Go into your project folder
cd shinyproxy-config/docker-compose-example
# Build all docker images
docker-compose build
# Run shinyproxy
docker-compose up -d shinyproxy
Visit: http://localhost:8080
To stop shinyproxy use docker-compose down
.
이 자료를 공유해주신 분께 무한한 감사를 드린다... So much Thank you.
https://github.com/kassambara/shinyproxy-config