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

Bug: Docker CLI Access #1385

Closed
2 tasks done
liketoeatcheese opened this issue Oct 20, 2022 · 4 comments
Closed
2 tasks done

Bug: Docker CLI Access #1385

liketoeatcheese opened this issue Oct 20, 2022 · 4 comments
Labels
bug Something isn't working topic:docker This is related to the Docker container triage This issue is new

Comments

@liketoeatcheese
Copy link

Describe the bug

Hi team,

Based on the documentation it said that the surrealdb's docker image contains fully functional CLI, however, I'm having issues accessing it.

I'm not sure how to access the "surreal" command from my local computer which hosts the docker container, so I tried to sh to the container via the following command:
docker exec -it {{docker_id}} /bin/sh

But I got an error of command not found, so I inspected the image by the following command:
docker inspect surrealdb/surrealdb:latest

And the CMD sections showed null, while it should have /bin/sh, or /bin/bash within it so I can use it to access the DB. I assume it's one of the parts that should be included within the image build?

Any thoughts would be great, if you think I'm missing something, I'm happy to be pointed in the right direction.

Steps to reproduce

Create a fresh surrealdb
docker run --rm --name surrealdb -p 127.0.0.1:8000:8000 surrealdb/surrealdb:latest start --log trace --user root --pass root memory

Try surreal from the localhost command line (shouldn't work)

SSH to the container
docker exec -it {{docker_id}} /bin/sh

Inspect the image:
docker inspect surrealdb/surrealdb:latest

Expected behaviour

Be able to ssh to the container to use the CLI

SurrealDB version

Release v1.0.0-beta.8

Contact Details

williampham198@gmail.com

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@liketoeatcheese liketoeatcheese added bug Something isn't working triage This issue is new labels Oct 20, 2022
@Franchise-x
Copy link

docker exec -it {container name} /surreal sql -c http://localhost:8000 -u root -p root --ns {namespace} --db test --pretty

@RonB
Copy link

RonB commented Nov 1, 2022

I can confirm this issue using a docker-compose file.
I added
stdin_open: true
tty: true
to the service but i don't get an interactive shell or bash. Probably not available in te docker image

@LeopoldBriand
Copy link
Contributor

Hi, if it can be useful I launch the database with this docker file configuration:
Dockerfile

FROM busybox:1.35.0-uclibc as busybox

FROM surrealdb/surrealdb:1.0.0-beta.8
COPY --from=busybox /bin/sh /bin/sh
COPY --from=busybox /bin/mkdir /bin/mkdir
COPY --from=busybox /bin/cat /bin/cat
COPY --from=busybox /bin/chmod /bin/chmod
ENTRYPOINT /surreal start --log debug --user $DB_USER --pass $DB_PASSWORD memory

docker-compose.yml

version: '3'

services:
  db:
    env_file:
      - ./database/.env
    build:
      args:
        - DB_USER=${DB_USER}
        - DB_PASSWORD=${DB_PASSWORD}
      context: ./database
      dockerfile: Dockerfile
    image: db
    ports:
      - 8000:8000

.env

DB_USER=User
DB_PASSWORD=Password

For further explanation, I borrow from the busibox image the execution requirements that are not in the distroless image. This also allows to run the database as a sh command and to include some environment variables.
If anyone finds another method without an intermediate build, I'm interested.

@kearfy kearfy added the topic:docker This is related to the Docker container label Jan 18, 2024
@sgirones
Copy link
Contributor

the CLI is part of the surreal binary, so you can execute the command @Franchise-x shared.

I assume based on the comments that the real issue is how to connect to a SurrealDB Server running in a container, and for that there are different options:

  • Local: start the Docker container with --net=host so the CLI in container A can access the server started in container B.
  • Docker Compose: same as with local, but instead of host you need to choose the network created by docker-compose
  • Use the -dev variant: We recently released a -dev Docker image variant that is "dev friendly" and contains a shell that you can exec into (i.e. surrealdb/surrealdb:latest-dev vs surrealdb/surrealdb:latest)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working topic:docker This is related to the Docker container triage This issue is new
Projects
None yet
Development

No branches or pull requests

6 participants