I would like to know if it would be possible to somehow copy file/folder from inside docker to host but copying itself is executed form inside docker.
The reason is that, for example:
When I was searching for a solution I've seen this command a lot docker cp <containerId>:/file/path/within/container /host/path/target
however this is executed from HOST. I want to make the whole process automated.
Possible solution of course is to not use docker but straight-up SSH, that's what I'm doing now, but that is not the best option IMO.
Here is example of my .gitlab-ci.yml
file that will explain what I want to achieve.
image: ubuntu:16.04
build:
stage: build
script:
- apt-get update
- apt-get upgrade -yy
- apt-get install hugo -yy # Static site generator
- hugo build # Build the website
- cp -R ./build/* /var/www/my-website/ # Copy to the web root
Here is my runner configuration
[[runners]]
name = "DOCKER-TEST"
url = "https://gitlab.com/ci"
token = "{{token}}"
executor = "docker"
[runners.docker]
tls_verify = false
image = "ubuntu:16.04"
privileged = true
disable_cache = false
volumes = ["/cache", "/home/stan:/builds/stanislavromanov/test-docker:rw"]
[runners.cache]
Insecure = false
You should be able to set a Docker volume where a directory in the container is mounted to a directory of the host.
In case of GitLab CI runners this can be specified during runner registration or later by modifying /etc/gitlab-runner/config.toml. Example:
[[runners]]
url = "https://gitlab.com/ci"
token = TOKEN
executor = "docker"
[runners.docker]
tls_verify = false
image = "ubuntu:16.04"
privileged = true
disable_cache = false
volumes = ["/path/to/bind/from/host:/path/to/bind/in/container:rw"]
See documentation for more info.
Copying from a container to the host is not possible with something like docker cp
. What you can do though is to mount the host-directory into the container, e.g.:
$ docker run ... -v /var/www/my-website:/website-on-host ...
and adapt your cp
command in .gitlab-ci.yml
as follows:
cp -R ./build/* /website-on-host/ # Copy to the web root
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With