How it works
Note
We consider that you have configure previously a Dockerfile
file according to instructions described in Adapting the Dockerfile to your needs section
Note
You need to install on your machine Docker and docker-compose
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.
In this use case, Compose is used with only one container but permits to launch shiny-server in order to help you to develop your shiny app under construction.
Below, the content of docker-compose.yaml
file. This file contains dedicated options to run the docker container with shiny-server service taking into account volume and port options.
1version: '3.4'
2services:
3 shiny-server:
4 build:
5 context: .
6 user: 'shiny:shiny'
7 volumes:
8 - ./my_project:/srv/shiny-server/
9 - ./logs:/var/log/shiny-server
10 ports:
11 - '3838:3838'
1version: '3.4'
2services:
3 shiny-server:
4 build:
5 context: .
6 command: [
7 'shiny',
8 'run',
9 '--host',
10 '0.0.0.0',
11 '--port',
12 '3838',
13 '--reload',
14 './app.py'
15 ]
16 user: 'shiny:shiny'
17 volumes:
18 - ./my_project:/srv/shiny-server/
19 - ./logs:/var/log/shiny-server
20 ports:
21 - '3838:3838'
Note
Your are free to change/modify folder name. Don’t forget to put your name at line 8.
Note
app.py
We described only some options used in the docker-compose
file. If you want to learn more, please see official documentation
Volumes
Volume option permits to connect local folder to folder inside the containers.
The command is compose of two fields separated by colon characters ( :
) :
local path of folder you want to mount
path of the folder in the container you want to connect.
Syntax : /host/path
:/container/path
Here, the command line 8 permits to mount the local folder named ./my_project
with the folder in the container where the shiny app is stored, /srv/shiny-server/
.
Thanks to this mount, you can modify files in your app directly from you local computer and modifications will applyed in the container.
Warning
In the previous command, you “bind-mount” a local directory into a non-empty directory on the container, the container directory’s existing contents are obscured by the bind mount. This can be beneficial, such as when you want to test a new version of your application without building a new image.
Another folder is also mounted with the line 9. The logs
folder permits to retrieve easily the log file linked to your app.
This folder have to be writable by the user shiny
, so simply allows everyone to write in it with:
chmod a+w logs/
Note
Logs and error logs are also visible on STDOUT.
Port
Port option permits to specify the HOST PORT
and the CONTAINER PORT
used for teh shiny-server service.
Here, we use the same port 3838 in the both case.
Command
command
instruction (lines 6 at 15) in order to reload the shiny-server after modification in your script.Run your container
Note
logs
folder.chmod a+w logs/
Now, you have all folder structure and configuration files. You are ready to run locally your shiny app. One command line is enough.
Dockerfile
and docker-compose.yaml
are stored.docker-compose up --build
Note
Administrate your container
By default, the name of the image build by docker-compose
command depends of the project and the service name (Services are built once and then tagged, by default as project_service
.)
See details docker compose build
Some usefull command line :
Start the containers in detached mode :
docker-compose up --build -d
View the status of the containers :
docker container ls
Or
docker ps
Stop the container use :
docker-compose stop
Stop and remove containers :
docker-compose down
Remove old builds :
Built containers can stack up on your local computers and eat disk space. It’s recommended to purge old built image from time to time with the following command line:
docker system prune -a