Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Support docker-compose #19

Open
NilsLattek opened this issue Dec 19, 2023 · 3 comments
Open

Feature request: Support docker-compose #19

NilsLattek opened this issue Dec 19, 2023 · 3 comments

Comments

@NilsLattek
Copy link

When using devcontainers with Github codespaces it is possible to reference a docker-compose file in the devcontainer.json:

{
    "name": "C# (.NET) and PostgreSQL",
    "dockerComposeFile": "docker-compose.yml",
    "service": "app",
    "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
   // ...
}

Full example: https://github.com/devcontainers/templates/blob/main/src/dotnet-postgres/.devcontainer/docker-compose.yml

This will bring up one pod which runs the postgres database and a second one which you can use to develop the application. Both pods are linked so that the postgres db can be accessed from the dev container.

Right now this is not possible with the kubernetes provider: [12:28:25] info devcontainer up: find docker compose: docker compose is not supported by this provider, please choose a different one

Is that something which is planned for the future?

@FabianKramm
Copy link
Member

@NilsLattek thanks a lot for the issue! Currently its a difficult task to translate docker compose to Kubernetes yamls as there are many limitations and projects such as kompose don't really work with our use case. If you have any other idea how to implement this, please let us know.

@NilsLattek
Copy link
Author

Thanks for the information @FabianKramm. I think you can judge this better than I do.
Feel free to close the issue or leave it open if you want to keep it as a possibility in the backlog.

@felipecrs
Copy link

felipecrs commented Apr 2, 2024

I would propose a different approach to this problem:

Make the devpod pod be a fully docker-capable container, with docker-compose. And then, INSIDE this pod, you can devcontainer build and devcontainer up.

This would make devpod a little more like Codespaces, with the difference being that Codespaces provides a full blown VM as the parent "container" instead.

For prototyping you can use ghcr.io/felipecrs/devcontainer, as it provides a fully capable docker within the pod (needs privileged: true), including docker-compose.

I don't have any concerns with privileged: true, but Sysbox can be used if there's any. ghcr.io/felipecrs/devcontainer is compatible with it (when using Sysbox, you don't need privileged: true).

Here's a simple devpod.yaml to get started:

apiVersion: v1
kind: Pod
metadata:
  name: devpod
spec:
  containers:
    - name: devpod
      image: ghcr.io/felipecrs/devcontainer:2
      imagePullPolicy: Always
      securityContext:
        privileged: true
      volumeMounts:
        - mountPath: /var/lib/docker
          name: docker-data
      terminationMessagePolicy: FallbackToLogsOnError
      resources:
        limits:
          memory: "8G"
          ephemeral-storage: "8Gi"
          cpu: "4"
        requests:
          memory: "8G"
          ephemeral-storage: "8Gi"
          cpu: "4"
  automountServiceAccountToken: false
  enableServiceLinks: false
  dnsPolicy: Default
  volumes:
    - name: docker-data
      ephemeral:
        volumeClaimTemplate:
          spec:
            storageClassName: local-path
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 24Gi
$ k3d cluster create

$ kubectl apply -f devpod.yaml

$ kubectl wait --for=condition=ready pod/devpod

$ kubectl exec -it devpod -- docker version

$ kubectl exec -it devpod -- bash -exc 'pkgx install node npm; npm i -g @devcontainers/cli; devcontainer --version'

$ kubectl exec -it devpod -- git clone https://github.com/loft-sh/devpod

$ kubectl exec -it devpod -- devcontainer build --workspace-folder devpod

$ kubectl exec -it devpod -- devcontainer up --workspace-folder devpod

$ kubectl exec -it devpod -- devcontainer exec --workspace-folder devpod go version

@FabianKramm what do you think? I'm eager for such thing as most of my .devcontainers are either based on docker compose or rely on mounting the docker socket like -v /var/run/docker.sock:/var/run/docker.sock (like the official docker-outside-of-docker feature), which devcontainer doesn't support today either.

One thing that needs to be ensured is that the docker data-dir is contained within the workspace volume.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants