0

I want to run a pre-existing Docker image like so:

docker run -d --name cdt-selenium selenium/standalone-firefox:3.4.0-chromium

So there is no Dockerfile that I control for this image. However, I would like to copy some files into this container.

If I did control the Dockerfile, I would like to run these commands:

RUN mkdir -p /root/cdt-tests/csv-data
COPY ./csv-data/* /root/cdt-tests/csv-data

Is there a way to run those commands in the same line as the Docker run command above?

I tried this:

docker run -d --name cdt-selenium selenium/standalone-firefox:3.4.0-chromium
docker exec cdt-selenium mkdir -p /root/cdt-tests/csv-data
docker cp cdt-selenium:/root/cdt-tests/csv-data ./csv-data

but I get a permissions error on the docker exec line

3
  • ah, perhaps I can use docker exec, after calling docker run Commented May 24, 2017 at 18:37
  • Why aren't you importing these files as a volume? Commented May 24, 2017 at 19:55
  • @BMitch yes, I agree, that was my other question - stackoverflow.com/questions/44146561/… current question here is a workaround, because I could not figure out how to get volumes to work... Commented May 24, 2017 at 20:54

1 Answer 1

3

All images have a FROM line, and that can be any other image. So you can make a Dockerfile with:

FROM selenium/standalone-firefox:3.4.0-chromium
USER root
RUN mkdir -p /root/cdt-tests/csv-data
COPY ./csv-data/* /root/cdt-tests/csv-data
USER seluser

that will build your own image with your commands run.

You'd build it and create your own tag:

docker build -t alexander/selenium:3.4.0-chromium .

And then run it:

docker run -d --name cdt-selenium alexander/selenium:3.4.0-chromium

Edit: the exec command you ran failed because docker runs this container as a different user. You can see that in their Dockerfile. To solve that, run the exec with the root user option (-u root):

docker exec -u root cdt-selenium mkdir -p /root/cdt-tests/csv-data
Sign up to request clarification or add additional context in comments.

11 Comments

thanks, I will try this - first though I'd like to try the docker exec/docker cp method - I updated the question - any idea how to get around that permissions problem I mention?
I've updated the answer to cover the seluser that Selenium uses inside their container.
thanks, also using sudo seemed to work (which is surprising) => docker exec cdt-selenium sudo mkdir -p /root/cdt-tests/csv-data
is selenium server really ok with absolute paths to files on the fs?
yeah both these techniques seem to work without errors, but selenium still cannot find the files at /root/cdt-tests/csv-data/X...not really sure what's happening, any ideas?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.