C
Coder.com2mo ago
saun

How to build a custom private image using coder's docker template?

I need to access private docker registry to use the image there to build a workspace using the coder's default docker template
42 Replies
Codercord
Codercord2mo ago
<#1345345558914666557>
Category
Help needed
Product
Coder (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
Scott
Scott2mo ago
@saun - Maybe this will help you. https://coder.com/docs/tutorials/image-pull-secret
Template ImagePullSecrets | Coder Docs
Creating ImagePullSecrets for private registries
From An unknown user
From An unknown user
saun
saunOP2mo ago
hey, this is for kubernetes, is anything there for docker? new to this, so not sure how to use it @Ryan do you know how to do this?
Ryan
Ryan2mo ago
Assuming you meant to tag a different Ryan?
saun
saunOP2mo ago
mb, i got to know you might knew
saun
saunOP2mo ago
checked, still not sure what I am doing wrong
saun
saunOP2mo ago
saun
saunOP2mo ago
is this correct, because this is not working? @Scott do you know this?
Scott
Scott2mo ago
What does "not working" mean? Any errors or unexpected results from steps you do other than "it doesn't work"?
saun
saunOP2mo ago
what is happening is, it is not using my private docker image, it is fallbacking to the ubuntu image always So I am not seeing any error if I remove the fallback, the workspace becomes idle and not responsive, so I have to stop it, without giving any errors
Scott
Scott2mo ago
I'd suggest reducing your template file to only the necessary parts for loading the container image and getting it running as a workspace. I'm also assuming you put in "registry.example.com" because you don't wish to share your registry address? If not, that is your first problem.
saun
saunOP2mo ago
yes I am putting my correct registry
saun
saunOP2mo ago
here is some updated code
saun
saunOP2mo ago
getting this error now, Error: Unable to read Docker image into resource: unable to pull image registry.example.com/image:0.0.1: error pulling image registry.exampl.com/image:0.0.1: Error response from daemon: unauthorized: authentication required on main.tf line 242, in resource "docker_image" "main": 242: resource "docker_image" "main" {
Scott
Scott2mo ago
Try removing these lines:
resource "docker_image" "main" {
name = local.image_name
keep_locally = true
}
resource "docker_image" "main" {
name = local.image_name
keep_locally = true
}
And see what happens. Oh. And change the image here:
resource "docker_container" "workspace" {
count = data.coder_workspace.me.start_count
image = docker_image.main.name # <- here!!!
resource "docker_container" "workspace" {
count = data.coder_workspace.me.start_count
image = docker_image.main.name # <- here!!!
Change it to the image name used within your private registry.
saun
saunOP2mo ago
Error: Unable to create container with image registry.example.com/example:0.0.1: unable to pull image registry.example.com/example:0.0.1: error pulling image registry.example.com/example:0.0.1: Error response from daemon: unauthorized: authentication required on main.tf line 242, in resource "docker_container" "workspace": 242: resource "docker_container" "workspace" { gettin this error
Scott
Scott2mo ago
What is the environment Docker is running on? Is it your local computer? Or is it a VM? Just curious for now. Also, try hard coding your credentials to be sure they are getting through. Also, what is the authentication method your registry uses?
saun
saunOP2mo ago
its a linux server it used curl -u username:password https:://registry.example.com/v2/_catalog output gives me the images so everything is fine there even pulled the image so thats also working
Scott
Scott2mo ago
Sorry then. I'm at a loss for more things to try. 🤷🏻
saun
saunOP2mo ago
thanks for the help
Phorcys
Phorcys2mo ago
check that the registry host you've inputted in registry_auth.address matches the same host that would be in ~/.docker/config.json when using the Docker CLI
saun
saunOP2mo ago
i am hard coding it
No description
Phorcys
Phorcys2mo ago
not what i meant
saun
saunOP2mo ago
No description
Phorcys
Phorcys2mo ago
here, you're setting "registry.example.com", but when logging in to the registry via the CLI on another, is it the same host that ends up inside the docker config? e.g is the config exactly the same value or is there some port?
{
"auths": {
"registry.example.com": {},
},
}
{
"auths": {
"registry.example.com": {},
},
}
saun
saunOP2mo ago
yup same
Phorcys
Phorcys2mo ago
try reusing the config
saun
saunOP2mo ago
"auths": { "registry.example.com": { "auth": "somehting" } } how can I pass this config file to the terrform?
Phorcys
Phorcys2mo ago
you can set config_file_content instead of username/password you probably won't want to keep this but it's just to see if it actually works
saun
saunOP2mo ago
where should I store the config file, i am lost, will the template uses the coder host's config?
Phorcys
Phorcys2mo ago
that or you can give it a path via config_file, but it's probably simpler to set content when using config_file_content, you just set the value with the json contents
saun
saunOP2mo ago
got this docker log for the workspace container
saun
saunOP2mo ago
No description
saun
saunOP2mo ago
screen is frozen at
No description
Phorcys
Phorcys2mo ago
install curl inside your registry image the Coder agent install script needs either one of these tools to download and run the agent
saun
saunOP2mo ago
ok I will install curl, wget and busybox
Phorcys
Phorcys2mo ago
you don't need all three, the script just tries these to see if there's any installed i'd recommand installing only one, and curl is likely the best candidate
saun
saunOP2mo ago
thanks so much it is working now can I contribute in some way, like adding this template somewhere or writing a blog or something for this?
Codercord
Codercord2mo ago
@bpmct closed the thread.
bpmct
bpmct2mo ago
A blog would be awesome and we would happily repost (cc @Marco). We are also working on a community registry with a bunch of templates. Stay tuned there
Marco
Marco2mo ago
@saun a blog would be awesome. Let me know if you end up writing it and I will make sure to repost it.

Did you find this page helpful?