Introduction
This how-do is to demonstrate using artifact stanza with mode=”file” to copy a file from an external source to a specific folder in a docker container.
Problem
For operator who desires to keep the existing files on the target directory, they would need to utilize an existing allocation directory /local without having to map additional mount point inside the docker container.
Solution
In this test image, it demonstrates using /usr/share/ as the target directory in the container :
task "redis" {
driver = "docker"
config {
image = "redis:3.2"
port_map {
db = 6379
}
volumes = ["local/ojdbc8.jar:/usr/share/ojdbc8.jar"]
}
artifact {
source = "https://repo1.maven.org/maven2/com/oracle/database/jdbc/ojdbc8/19.6.0.0/ojdbc8-19.6.0.0.jar"
destination = "local/ojdbc8.jar"
mode = "file"
}
root@ip-172-31-40-48:~# nomad alloc exec e4a /bin/bash
root@0a6ec15b292c:~# ls /usr/share/
adduser common-licenses doc-base keyrings menu perl5
base-files debconf dpkg libc-bin misc pixmaps
base-passwd debianutils gcc-6 lintian ojdbc8.jar tabset
bash-completion dict gdb locale pam terminfo
bug doc info man pam-configs zoneinfo
Notice that the file ojdbc8.jar showed up with previously existing files in that target directory /usr/share as intended for in this example.
Essentially you are creating a mount point in the container like below so the parallel files are visible to you instead of being mounted over like previous example shown last week:
"Mounts": [
{
"Type": "bind",
"Source": "/opt/nomad/data/alloc/e4a756ef-71c6-9206-a28d-ee962fe2fc46/redis/local/ojdbc8.jar",
"Destination": "/usr/share/ojdbc8.jar",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},