Reputation: 192
I am using default image and my requirement is to run a few Linux commands when I run docker-compose file. Os is redhat. This is my docker-compose file
version: '3.4'
services:
rstudio-package-manager:
image: 'rstudio/rstudio-package-manager:latest'
restart: always
volumes:
- '$PWD/rstudio-pm.gcfg:/etc/rstudio-pm/rstudio-pm.gcfg'
command: bash -c mkdir "/tmp/hello"
ports:
- '4242:4242'
This is the error:
rstudio-package-manager_1 | mkdir: missing operand
rstudio-package-manager_1 | Try 'mkdir --help' for more information.
Any help would be appreciated
EDIT
I have to run a few commands after the container starts. It can be added as a bash script too. For that, I tried this
version: '3.4'
services:
rstudio-package-manager:
privileged: true
image: 'rstudio/rstudio-package-manager:latest'
restart: always
environment:
- RSPM_LICENSE=1212323123123123
volumes:
- './rstudio-pm.gcfg:/etc/rstudio-pm/rstudio-pm.gcfg'
- './init.sh:/usr/local/bin/init.sh'
command:
- init.sh
ports:
- '4242:4242'
Inside init.sh is this
alias rspm='/opt/rstudio-pm/bin/rspm'
rspm create repo --name=prod-cran --description='Access CRAN packages'
rspm subscribe --repo=prod-cran --source=cran
And that also didn't work. Can anyone helpme out?
Upvotes: 1
Views: 11235
Reputation: 130
I know it is probably late but if anyone stumbles upon this, you can try this:-
version: '3.4'
services:
rstudio-package-manager:
image: 'rstudio/rstudio-package-manager:latest'
restart: always
volumes:
- '$PWD/rstudio-pm.gcfg:/etc/rstudio-pm/rstudio-pm.gcfg'
command:
- bash
- -c
- |
- mkdir "/tmp/hello"
ports:
- '4242:4242'
Upvotes: 0
Reputation: 265928
Based on your edit, it doesn't sound like you want to change the command
when running a container, but you want to create a derived image based on an existing one.
You want a Dockerfile
which modifies an existing image and add your files/applies your modifications.
docker-compose.yml
:
version: '3.4'
services:
rstudio-package-manager:
privileged: true
build:
context: folder_with_dockerfile
image: your_new_image_name
restart: always
environment:
- RSPM_LICENSE=1212323123123123
volumes:
- './rstudio-pm.gcfg:/etc/rstudio-pm/rstudio-pm.gcfg'
- './init.sh:/usr/local/bin/init.sh'
ports:
- '4242:4242'
folder_with_dockerfile/Dockerfile
:
FROM rstudiol/rstudio-package-manager:latest
RUN alias rspm='/opt/rstudio-pm/bin/rspm' && \
rspm create repo --name=prod-cran --description='Access CRAN packages' && \
rspm subscribe --repo=prod-cran --source=cran
RUN commands in next layer
RUN commands in third layer
Then build the new image with docker-compose build
and start normally. You could also run docker-compose up --build
to build & run.
Upvotes: 0
Reputation: 265928
You are passing 3 arguments to bash
:
-c
mkdir
/tmp/hello
but you need to pass only two:
-c
mkdir /tmp/hello
In other words: -c
expects a single "word" to follow it. Anything after that is considered a positional parameter.
Therefore:
bash -c 'mkdir /tmp/hello'
Upvotes: 4