3

I'm using jenkins to build docker containers and send the completed image to AWS S3 bucket.

I'm trying to get a file that is pulled from Github onto the docker image and then package it up into a docker image.

Currently I have jenkins completing the git pull and building the container but I can not get it to copy the files to the container. I get this error:

Building in workspace /var/lib/jenkins/jobs/copy-to-docker/workspace
[workspace] $ /bin/sh -xe /tmp/hudson5108979322433439821.sh
+ docker cp /var/lib/jenkins/jobs/Move git pull files to docker/workspace/html/:index.html
+ :/var/lib/docker/containers
/tmp/hudson5108979322433439821.sh: 2: /tmp/hudson5108979322433439821.sh: :/var/lib/docker/containers: not found
docker: "cp" requires 2 arguments.
See 'docker cp --help'.

Usage:    docker cp [OPTIONS] CONTAINER:PATH LOCALPATH|-
  docker cp [OPTIONS] LOCALPATH|- CONTAINER:PATH

Copy files/folders between a container and the local filesystem
Use '-' as the source to read a tar archive from stdin
and extract it to a directory destination in a container.
Use '-' as the destination to stream a tar archive of a
container source to stdout.
Build step 'Execute shell' marked build as failure
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Finished: FAILURE`

I also want to change the container ID and name of the container but I have looked through the docker docs and I have not been able to find a way to do this?

timss
  • 9,982
  • 4
  • 34
  • 56
zextia
  • 31
  • 1
  • 2

1 Answers1

0

I don't have any experience with Jenkins but as for docker specific features I can attempt to help you.

To copy files to a running docker container, you'll want to do something along the lines of:

docker cp foo.txt mycontainer:/foo.txt
docker cp mycontainer:/foo.txt foo.txt

see: Copying files from host to Docker container

If you want to copy it as you create the docker image, you want to do something(inside your Dockerfile) along the lines of:

COPY \$foo /quux # COPY $foo /quux

see: https://docs.docker.com/engine/reference/builder/

As for the container ID, I believe that you cannot set these directly, and you shouldn't really need to as across docker you can substitute the ID for the Name of the container in every instance that I've dealt with.

If you want to rename a docker running docker container you want to use:

docker rename [OPTIONS] OLD_NAME NEW_NAME

See: https://docs.docker.com/engine/reference/commandline/rename/

Otherwise, you can launch a container with a specific name using:

docker run --name containername mysql

Hope this helps :)

Community
  • 1
  • 1
Ozzadar
  • 518
  • 1
  • 3
  • 10