#CMD and EXPOSE and WORKDIR

1 messages · Page 1 of 1 (latest)

near steppe
#

Hi everyone,

We are enjoying the dagger experience so far but i'm struggling with specifying a CMD and an EXPOSE.

I have something like: PythonSDK

container = container.with_workdir('/widgets')
container = container.with_exposed_port(80)
container = container.with_entrypoint(["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"])

And then it gets published to a private ECR with no problems.

When we inspect the image no CMD, no WORKDIR, no EXPOSE and NO ENTRYPOINT are added.

When we try to docker run it fails.

Are we missing something?
Thanks in advance

split flint
#

Hi! Normally there should be an entrypoint... If you want to set CMD, that's with container.with_default_args.

#

But your understanding of with_entrypoint is correct. Assuming you're pushing the result of that pipeline, the image should have an ENTRYPOINT

#

same with EXPOSE, but it's possible that it's not implemented yet

near steppe
#

Thanks @split flint ill give it a try with default args

#

with the EXPOSE and ENTRYPOINT, is there any workaround for that?

#

and with WORKDIR

#

this container = container.with_default_args(["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]) worked

near steppe
#

even though im not being able to make it work, the with_default_args added the CMD properly, but it seems the WORKDIR instruction it is being ignored

#

CMD and EXPOSE and WORKDIR

split flint
#

To summarize my understanding:

  • with_default_args correctly sets CMD in the image ✅
  • withExec should use the content of CMD from an image, but doesn't ❌
  • with_entrypoint should set ENTRYPOINT in the image, but doesn't ❌
  • with_exposed_port should set EXPOSE in the image, but doesn't ❌
  • with_workdir should set WORKDIR in the image, but doesn't ❌

Is that right?
(EDIT: add workdir)

near steppe
#

yes, and also i dont see the WORKDIR instruction, therefore the container can't start properly

split flint
#

I guess I should make this a table... One column for image push, one column for image pull

near steppe
#

so when docker run the CMD command runs from a different location

split flint
#

ah ok

#

Let me open an issue to track all this

near steppe
#

good, i can provide more details if needed

#

at this moment im blocked with this, im trying to make it run somehow, basically im replicating this Dockerfile

FROM python:3.10.10-alpine3.17
WORKDIR /bookingservice
COPY ./requirements.txt  /bookingservice/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /bookingservice/requirements.txt
COPY app /bookingservice/app
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
#

everything looks great up until i run it

near steppe
#

Hello there, any suggestions on how to work around this? I'm using version Python SDK 0.4.2

#

Maybe if I just start from a Dockerfile containing this instructions, then do the dagger magic and then publish

#

I wonder how people is using it

maiden tendon
#

👋 will try to help async, maybe others can step in too

do you have a full code snippet that reproduces this issue? I think everything but EXPOSE should work. (WithExposedPort doesn't actually set that value atm - an oversight.)

novel cove
#

@near steppe this should do the trick

package main

import (
    "context"
    "os"

    "dagger.io/dagger"
)

func main() {
    ctx := context.Background()

    // create Dagger client
    client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
    if err != nil {
        panic(err)
    }
    defer client.Close()

    client.Container().
        Build(client.Directory().WithNewFile("Dockerfile", `
FROM alpine
EXPOSE 8080
ENTRYPOINT foo
    `)).
        Export(ctx, "./export.tar")
    // create Redis service container
    if err != nil {
        panic(err)
    }
}

@maiden tendon ref: https://github.com/dagger/dagger/issues/3886

GitHub

What are you trying to do? Allow to set OCI image config through cloak. Some other users in Discord are requesting this also. https://discord.com/channels/707636530424053791/1042489428788138025 htt...

#

basically as Solomon mentioned, seems like the only thing that can be currently set is CMD through DefaultArgs and LABELS. ENTRYPOINT and EXPOSE can't seem to be set otherwise.

maiden tendon
near steppe
#

thanks for the help guys! i'll try this approaches, also the WORKDIR instruction is not being added and that's being the main problem for myself, because the CMD command runs in a different location than intended

novel cove
#

@maiden tendon you're correct. ENTRYOPOINT is set correctly

#

@near steppeworkingdir should be also working as Alex mentions

#
package main

import (
    "context"
    "os"

    "dagger.io/dagger"
)

func main() {
    ctx := context.Background()

    // create Dagger client
    client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
    if err != nil {
        panic(err)
    }
    defer client.Close()

    client.Container().From("alpine").WithWorkdir("/test").
        Export(ctx, "./export.tar")
    // create Redis service container
    if err != nil {
        panic(err)
    }
}

^ that produces a tarball with the correct WorkingDir

novel cove
near steppe
#

i'll give this a try and get back to you, gracias guys

#

one more thing, im not familiar with that tarball export, that will give me the Dockerfile?

novel cove
near steppe
#

oh i see! i can use that to verify if its built properly

novel cove
#

with that tar you can do docker load -i <export.tar> to load the image in your local docker daemon

oblique rivet