How can nomad' job from local docker images - docker

nomad docker image will be fetched from Docker Hub.But I have want use some local images.How can I use theme.(I dont want to use private repo)
Example I want to use local image test
> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test latest da795ca8a32f 36 minutes ago 567MB
job "test" {
datacenters = ["dc1"]
group "example" {
task "test" {
driver = "docker"
config {
image = "test"
}
resources {
cpu = 500
memory = 256
}
}
}
}
It's wrong !

I'm not sure if this can be treated as an answer or a "hack".
But if you want Nomad to use docker image that is already present on a node the image MUST NOT be tagged latest.
For testing I tag my images as IMAGE:local. This way Nomad uses it if present, pulls it from remote if not.

Looking at Nomad's source code here and here, it seems that using machine local images is not supported. That would make sense, as in a cluster environment with several nodes, the scheduler needs to be able to get the image irrespective of which machine the job is allocated to.
(One possible workaround would be to run a registry service within the Nomad cluster, and use whichever storage backend is most convenient for you)

Nomad now supports tar docker images.
here is an example
artifact {
source = "http://path.to/redis.tar"
}
config {
load = "redis.tar"
image = "redis"
}
However, the tar size may be too large to be resiliently transport and provisioned.

While #Miao1007 s answer works, you need to be aware of one thing. It seems that you you cannot use the tag latest or omit the tag altogether ( see the discussion here). You need to tag your docker build with some version number like
sudo docker build --tag dokr:1.0.0 .
sudo docker save dokr:1.0.0 > dokr-1.0.0.tar
then use the following in the job file
artifact {
source = "http://localhost:8000/dokr-1.0.0.tar"
}
config {
load = "go-docker-dokr-1.0.0.tar"
image = "go-docker-dokr:1.0.0"
}

Starting from version 0.9.0, Nomad checking whether the image has already been loaded.
Source code
Contributor comment
// We're going to check whether the image is already downloaded. If the tag
// is "latest", or ForcePull is set, we have to check for a new version every time so we don't
// bother to check and cache the id here. We'll download first, then cache.

Related

Using docker for only some processes in Nextflow

I am writing a pipeline in Nextflow, which contains multiple processes, where most of them use docker. Now I am trying to add a new process which includes only a python script to preprocess some results - no docker image needed.
However, I get the error Missing container image for process 'my_python_process'.
I define the docker images in nextflow.config as follows:
process {
withName:process1 {
container = 'some/image1:1.0'
}
withName:process2{
container = 'some/image2:1.0'
}
withName:process3{
container = 'some/image3:1.0'
}
}
docker {
enabled = true
}
I found a discussion, where they suggested using container = null for the process without container, but it still gives the same error, no matter what the process script contains.
Does anyone know what I'm missing please? Thank you!
With docker.enabled = true, Nextflow will try to run each process in a Docker container created using the specified image. You then get the error you're seeing when the container directive has not been specified for a particular process. The usual way is to just specify a 'base' or 'default' container for your workflow. You may want to choose one that comes with Python. Otherwise, Ubuntu would be a good choice in my opinion.
Note that the withName process selector has the highest priority1.
process {
container = 'ubuntu:22.04'
withName: my_python_process {
container = 'python:3.9'
}
withName: process1 {
container = 'some/image1:1.0'
}
withName: process2 {
container = 'some/image2:1.0'
}
withName: process3 {
container = 'some/image3:1.0'
}
}
docker {
enabled = true
}
I'm not aware of a way to disable Docker execution for a particular process, but nor would you really want to2. The above approach should be preferred:
Containerization allows you to write self-contained and truly
reproducible computational pipelines, by packaging the binary
dependencies of a script into a standard and portable format that can
be executed on any platform that supports a container runtime.
Furthermore, the same pipeline can be transparently executed with any
of the supported container runtimes, depending on which runtimes are
available in the target compute environment.

How to list locally-stored manifests

When I do docker manifest create ... this manifest is stored locally and it is not pushed to the registry until I do docker manifest push ... but I'm not sure where it lives in the meantime, before it is pushed.
I know that I can remove the locally-stored manifest with docker manifest rm ... but my goal is to clean up any forgotten manifests that I created, so how can I list all the locally-stored manifests?
I expected docker manifest ls but no such command exists.
Kind of surprised, that this is not documented anywhere. I had to investigate this myself by reading the source code of docker-cli:
The docker manifest create command is implemented in command/manifest/create_list.go. It eventually calls manifestStore.Save.
The manifestStore is obtained from dockerCli.ManifestStore(), which is implemented in command/cli.go like this:
func (cli *DockerCli) ManifestStore() manifeststore.Store {
// TODO: support override default location from config file
return manifeststore.NewStore(filepath.Join(config.Dir(), "manifests"))
}
So in short, you can list or remove all manifests by listing or removing the contents of ~/.docker/manifests (or more precisely ${DOCKER_CONFIG}/manifests).
This is not very elegant, but there's no better alternative at the moment AFAIK.

docker saved image, how to run?

I have a testlink docker image running (named 'otechlabs/testlink').
Question 1: How do I get the original url from which I downloaded it (I can't remember) ? I would like to see the instructions about how to run the container.
It's running so fine that I saved a commit of it to run in another machine.
Question 2: Should I remember the run parameters(I can't remember)?
The container was created around 3 months ago.
Question 3: Instead of save/load, should I export/import?
Since I don't remember how to run the image, then I guess I should skip this step, perhaps (someway) copying the image to just start it in another host.
Q1:
You can try looking up the image in docker hub. The name otechlabs/testlink suggests that the user otechlabs in dockerhub has an image called testlink.
Now, I tried looking up the user's profile here but it appears that he doesn't have anything uploaded yet, maybe it is a private image.
If you're lucky you might be able to find something useful from other people's testlink image page.
Example:
https://hub.docker.com/r/rodrigodirk/testlink/
Q2:
Not quite sure what you meant here. Well if you have a running container of it, you can always do a docker inspect [CONTAINER_ID] to revisit the parameters used for starting it.
Example:
"Config": {
"ExposedPorts": {
"5432/tcp": {},
"9001/tcp": {}
},
"Env": [
"affinity:container==47eea8a078ad47583b4f5343302e7939a6d5f04ad929a079d8d9ae7cbee96d6a",
"POSTGRES_USER=bigCat01"
]
}
Q1: If you did a 'docker pull' the image id contains the url; if the id does not contain a domain name, then it is by default dockerhub repository
Q2: (as mentioned by Samual) if you still have a container saved run 'docker inspect ' to display the startup param's
Q3: if you modified the container you can 'commmit' the changes, and you can also change the tag: 'docker tag old_tag new_tag'
To help move it around, you could change he tag to gcr.io/project-id/new_tag:version and push it to google's container registry (free 30 day trail, may be free beyond that if you keep resource usage low) in your project 'project-id'

has anyone created a docker container using cake?

Has anyone been able to create a cake.build file that compiles a c# code then creates a docker container? I would like to be able to create a docker file once the base code is built and then run the docker image in a container.
You can build and run Docker images from your Cake scripts using the Cake.Docker community addin.
Add #addin nuget:?package=Cake.Docker to the top of your build script and you can then use the DockerBuild alias to build your container. You can also optionally use DockerRun to run your container.
You can find full documentation on this addin on the website, including for DockerBuild (and DockerRun).
For example, assuming your Dockerfile in a folder called docker:
#addin nuget:?package=Cake.Docker
// the rest of your build script
Task("Docker-Build")
.Does(() => {
var settings = new DockerImageBuildSettings { Tag = new[] {"dockerapp:latest" }};
DockerBuild(settings, "./Docker");
});

How to get the container Id of the running container using docker-java?

I am running a container with name tag which allows me to identify it.In docker-java,it requires container id for most of the operations and i do not know how to get that using docker-java.Can anyone help me how to get the container Id for the running container?
For example:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8945dcd6195b e7a064b1705a "java '-Duser.time..." 4 days ago Up 20 seconds runDataMock
I am looking for a way by which i could get the ContainerId using the ContainerNames.
NOTE: I am aware of the below method which creates a new container and picks the id.
dockerClient.createContainerCmd(imageName).exec().getId()
You can filter the containers by status and by other properties using withXXX methods but there is not a WithNameFilter method in docker-java API. A workaround is to use a generic filter:
//get the docker client
DockerClient docker = DockerClientBuilder.getInstance(config).build();
//prepare command to retrieve the list of (running) containers
ListContainersCmd listContainersCmd = client.listContainersCmd().withStatusFilter("running");
//and set the generic filter regarding name
listContainersCmd.getFilters().put("name", Arrays.asList("redis"));
//finally, run the command
List<Container> exec = listContainersCmd.exec();
and that's it!
If you are working with a local Docker Daemon, you could use https://www.github.com/amihaiemil/docker-java-api, version 0.0.1 has just been released.
To iterate over all the running containers, all you have to do is the following:
final Containers containers = new LocalDocker(
new File("/var/run/docker.sock")
).containers();
for(final Container running : containers) {
System.out.println(running.containerId());
}
Study the README of the project, the motivational blogpost and the wiki, they are quite short :)
Since this original posting date, the docker-java-api has gone through some updates. To update #amihaiemill's original answer to the updated api the code should be
final Docker docker = new UnixDocker( new File( "/var/run/docker.sock" ) );
final Containers containers = docker.containers();
for ( final Container running : containers ) {
System.out.println( running.containerId() );
}
Thank you amihaiemil for your work on this project

Resources