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

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • ah, perhaps I can use docker exec, after calling docker run – Alexander Mills May 24 '17 at 18:37
  • Why aren't you importing these files as a volume? – BMitch May 24 '17 at 19:55
  • @BMitch yes, I agree, that was my other question - https://stackoverflow.com/questions/44146561/selenium-cannot-find-file-running-in-separate-container....the current question here is a workaround, because I could not figure out how to get volumes to work... – Alexander Mills May 24 '17 at 20:54

1 Answers1

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
BMitch
  • 231,797
  • 42
  • 475
  • 450
  • 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? – Alexander Mills May 24 '17 at 18:45
  • 1
    I've updated the answer to cover the seluser that Selenium uses inside their container. – BMitch May 24 '17 at 18:50
  • thanks, also using sudo seemed to work (which is surprising) => docker exec cdt-selenium sudo mkdir -p /root/cdt-tests/csv-data – Alexander Mills May 24 '17 at 18:52
  • is selenium server really ok with absolute paths to files on the fs? – Alexander Mills May 24 '17 at 18:53
  • 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? – Alexander Mills May 24 '17 at 19:10
  • one clue is, when I run this: docker exec -u root cdt-selenium echo $(ls -a /root/cdt-tests), it says that there is no such directory as /root/cdt-tests, so maybe that directory is not being created correctly, idk, very strange – Alexander Mills May 24 '17 at 19:11
  • aka, "ls: /root/cdt-tests: No such file or directory", weird. – Alexander Mills May 24 '17 at 19:13
  • Since Selenium is running as seluser inside the container, I doubt it can see files under /root. It may also depend on the file permissions of the source (host). – BMitch May 24 '17 at 19:54
  • This is on my local machine and the exec/cp commands complete successfully, so should not be permissions problem, but at the same time, the files don't appear to exist in the container, because the ls command fails. weird. – Alexander Mills May 24 '17 at 20:56
  • Selinium doesn't run on your local machine, it runs in a container, as a different user. – BMitch May 24 '17 at 21:45
  • Right, I am aware of that, and sometimes selenium might run an another machine altogether. That's what makes me think, that maybe the problem that I think I have, is not the problem I really have. – Alexander Mills May 24 '17 at 22:55