0

How would somebody use the Docker Engine API to stop a container, upload a file (from a url) to a path in a container, then run the start command again? I am running this image. The intention is to have a Minecraft Server then upload a plugin from a url and restart it. I have seen the docker cp command although it is best to be able to do it from the RESTful API.

SOFe
  • 7,867
  • 4
  • 33
  • 61

3 Answers3

1

You can copy files to a running container using docker cp, but I think what you really want to do is build a new image based on that other image.

Dockerfile

FROM nathjeid/pocketmine-mp:latest
ADD ./FileToCopy.txt /FolderToCopyTo

Then run docker build -t mycoolimage .

Result: You now have a docker image called "mycoolimage" that is identical to nathjeid/pocketmine-mp, plus the file you want to add.

If you want to get the file from a url rather than from your local file system you can use the RUN command in your Dockerfile and use curl. If the image doesn't already have curl on it you'll need to install it.

Docker cp docs page

Dockerfile reference

Docker build docs page

Andrew Roth
  • 1,063
  • 10
  • 18
1

If you want to do it in a running container use docker cp. A shell script like this should work:

wget http://example.com/file.out
docker cp file.out yourcontainer:/desired/path/file.out
docker restart yourcontainer

Alternatively you can use another container (named, for example, administrator) and share a volume with your plugins. The other container can be a restful server (ex. python flask or whatever) that uploads file to the shared volume.

If you want to start, restart the first container from the administrator container you must run the administrator container sharing the docker sock like this:

-v /var/run/docker.sock:/var/run/docker.sock

More explanations for docker restart from another container:

Is it possible to start a stopped container from another container

Alfonso Tienda
  • 3,442
  • 1
  • 19
  • 34
0

The <src> in the ADD instruction can be a remote file URL:

E.g.:

ADD https://www.example.com/hello.txt /tmp/

will download the file under /tmp

lainatnavi
  • 1,453
  • 1
  • 14
  • 22