I'm thinking of using Docker to build my dependencies on a continuous integration (CI) server, so that I don't have to install all the runtimes and libraries on the agents themselves. To achieve this I would need to copy the build artifacts that are built inside the container back into the host.
Is that possible?
You do not need to use
docker run
You can do it with
docker create
From the docs The docker create command creates a writeable container layer over the specified image and prepares it for running the specified command. The container ID is then printed to STDOUT. This is similar to docker run -d except the container is never started.
So, you can do
Here, you never start the container. That looked beneficial to me.
Mount a volume, copy the artifacts, adjust owner id and group id:
Mount a "volume" and copy the artifacts into there:
Then when the build finishes and the container is no longer running, it has already copied the artifacts from the build into the
artifacts
directory on the host.EDIT:
CAVEAT: When you do this, you may run into problems with the user id of the docker user matching the user id of the current running user. That is, the files in
/artifacts
will be shown as owned by the user with the UID of the user used inside the docker container. A way around this may be to use the calling user's UID:As a more general solution, there's a CloudBees plugin for Jenkins to build inside a Docker container. You can select an image to use from a Docker registry or define a Dockerfile to build and use.
It'll mount the workspace into the container as a volume (with appropriate user), set it as your working directory, do whatever commands you request (inside the container). You can also use the docker-workflow plugin (if you prefer code over UI) to do this, with the image.inside() {} command.
Basically all of this, baked into your CI/CD server and then some.
In order to copy a file from a container to the host, you can use the command
Here's an example:
Here goofy_roentgen is the name I got from the following command:
https://docs.docker.com/engine/reference/commandline/run/ https://docs.docker.com/engine/reference/commandline/cp/