我想在docker文件中添加多个脚本,并在容器启动时运行它。startup.sh是一个应用程序,只有当它启动并运行时,我们才能运行playbook.sh
version: '3.4'
services:
rstudio_package_manager:
privileged: true
image: 'rspm_gh:sid'
restart: always
build:
context: ./
dockerfile: ./Dockerfile
ports:
- 34242:4242
- 32121:2121
environment:
- RSPM_LICENSE=My license
volumes:
- ./playbook.sh/:/tmp/playbook.sh
- ./startup.sh/:/usr/local/bin/startup.sh
这是我的Dockerfile
FROM rstudio/rstudio-package-manager:latest
# Expose necessary ports
EXPOSE 4242/tcp
EXPOSE 2112/tcp
RUN ["chmod", "+x", "/usr/local/bin/startup.sh"]
# Specify the entry point and startup command
ENTRYPOINT ["tini", "--"]
CMD ["/usr/local/bin/startup.sh","/tmp/playbook.sh"]
启动.sh
#!/bin/bash
set -e
set -x
# Deactivate license when it exists
deactivate() {
echo "Deactivating license ..."
/opt/rstudio-pm/bin/license-manager deactivate >/dev/null 2>&1
}
trap deactivate EXIT
# Activate License
if ! [ -z "$RSPM_LICENSE" ]; then
/opt/rstudio-pm/bin/license-manager activate $RSPM_LICENSE
elif ! [ -z "$RSPM_LICENSE_SERVER" ]; then
/opt/rstudio-pm/bin/license-manager license-server $RSPM_LICENSE_SERVER
elif test -f "/etc/rstudio-pm/license.lic"; then
/opt/rstudio-pm/bin/license-manager activate-file /etc/rstudio-pm/license.lic
fi
# lest this be inherited by child processes
unset RSPM_LICENSE
unset RSPM_LICENSE_SERVER
# Start RStudio Package Manager
/opt/rstudio-pm/bin/rstudio-pm --config /tmp/temp/rstudio-pm.gcfg
这是我的playbook.sh文件
#!/bin/bash
alias rspm='/opt/rstudio-pm/bin/rspm'
rspm create repo --name=prod-cran --description='Access CRAN packages'
rspm subscribe --repo=prod-cran --source=cran
rspm sync --wait
如有任何帮助,将不胜感激
在docker映像中不能有多个入口点。但是,您可以使用替代方案来启动多个进程。
例如,您可以使用supervisor来管理您的流程
在您的集装箱中安装监督员
RUN apt-get install -y supervisor
将主管配置文件从主机复制到您的容器
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
[supervisord]
nodaemon=true
[program:playbook]
command=/bin/sh -c "/tmp/playbook.sh"
[program:startup]
command=/bin/sh -c "/usr/local/bin/startup.sh"
在Dockerfile中,使用此命令启动监管
CMD ["supervisord"]