'Nomad job for existing containers

I'm fairly new to nomad. From a nomad job, I specified a docker image. From what I understand, nomad will download the image and create it's own container and maintain that container. Is there a way for nomad to maintain a container that's already running? (I.e a container I had before I had set up nomad)

Thanks!



Solution 1:[1]

I highly doubt it. The nomad docker driver handles starting the container and maintaining the container lifecycle. I doubt there is a mechanism to reference a container that already exists, although you could likely write a driver (or extend the current docker driver) to add that functionality: https://www.nomadproject.io/docs/drivers/docker.html

Solution 2:[2]

Moving a running docker Container into a nomad cluster would be kinda against the idea of docker containers, because a Container should always be ephermeral. You can read more about this in the Docker guidlines. It says :

Create ephemeral containers The image defined by your Dockerfile should generate containers that are as ephemeral as possible. By “ephemeral”, we mean that the container can be stopped and destroyed, then rebuilt and replaced with an absolute minimum set up and configuration.

Also technically its only possible with a hacky workaround because nomad has no import functionality. If you are willing to stop the Container you can try to create a nomad task with the same image and then copy the docker Container files into the root of your nomad task folder, but this will not work as easy as recreating the container with a volume mount to your exported working directory.

You can prepare your own Docker Image and push it into a repository of a container registry like Docker Hub (Tutorial) or use a 3rd Party Registry like the GitLab container registry(Tutorial) and provide it to Nomad.

If you use a private registry with credential you can provide the registry credential directly in the config stanza of any docker task

task "server" {
    driver = "docker"
    config {
        image = "<private-registry-url>/<image-name>:<tag>"
        auth {
            username = "<private-registry-user>"
            password = "<private-registry-password>"
        }
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 maxm
Solution 2 Jiyan Akgül