What is Docker? Why Use Docker? Docker is a software tool that packages environments into images. Users can run these images in containers, ensuring an identical environment without the need for manual configuration.
Docker is a software tool that packages environments into images. Users can run these images in containers, ensuring an identical environment without the need for manual configuration.
Please note that the development environment for sglang is a Linux system.
nerdctl may be used as a replacement. nerdctl is fully compatible with Docker commands; simply replace the command with nerdctl xxx.Most Docker images are published on Docker Hub.
Please use the official sglang image: lmsysorg/sglang Tags | Docker Hub.
# Download image # docker pull <image-name> docker pull lmsysorg/sglang:latest
A downloaded image is like a compressed package, which must be extracted into a container to run. The host machine refers to the server.
The command format for running a container is:
docker run [OPTIONS] IMAGE [COMMAND]
IMAGE must be placed after OPTIONS and before COMMAND.-it Interactive terminal
--name <container-name> Container name
--shm-size <shared-memory-size> Shared memory size
--gpus all Allow access to GPUs
all unless specific GPU allocation is needed.-v <host-path>:<container-path> Volume mounting
<host-path> from the host machine to <container-path> in the container. Files and directories in the mounted path are shared between the host and container, with modifications reflected on both sides.-v ~/.cache/huggingface:/root/.cache/huggingface mounts the Hugging Face cache from the host, allowing the container to reuse downloaded models without redownloading.pwd command outputs the current directory path. Use -v $(pwd):<container-path> to mount the directory where docker run is executed.A complete command might look like this:
docker run -it --name <container-name> --shm-size 16g --gpus all -v <host-path>:<container-path> IMAGE
-p <host-port>:<container-port> Port mapping
<container-port> inside the container to <host-port> on the host, enabling external access.--network host Network sharing
--network host to share the network proxy.--network host, the -p option is ignored.-e <env-name>=<env-value> Environment variables
<env-name> to <env-value>.--ipc=host Inter-process communication namespace sharing
--shm-size.-d Runs the container in the background; the container does not stop when exiting the terminal.--rm Automatically removes the container upon exit.docker pull lmsysorg/sglang:latestdocker pull lmsysorg/sglang:devYou can specify commands to run or restart within the container.
Some common cases:
docker run -it [other OPTIONS] <image-name> bash
sglang server inside the container (running on port 30000) and map it to port 30000 on the host for external access.HF_TOKEN to specify the model token.docker run -p 30000:30000 --env "HF_TOKEN=hf_xxx" [other OPTIONS] <image-name> python3 -m sglang.launch_server [other parameters]
docker ps View running containers.docker ps -a View all containers.Exit the session and stop the container:
exitCtrl + DExit the session while keeping the container running in the background:
Ctrl + P, then Ctrl + Q. (May not work in some IDEs due to shortcut conflicts.)-d when running docker run; the container remains running after exiting.Stop a running container:
docker stop <container-name>Note: A container automatically stops when the COMMAND finishes execution.
docker restart <container-name>A container must be running before attaching.
docker exec -it <container-name> bash Start an interactive session inside the container.exec command runs a command inside a running container and can also modify environment variables.The container must be stopped first:
docker rm <container-name>--rm when running docker run, so the container is automatically deleted upon exit.TODO
TODO
Please make sure to install the Devcontainer extension in VSCode.
In the folder you want to open inside the docker container create a folder .devcontainer.
In the .devcontainer create a devcontainer.json like so:
{ "name": "simon", "build": { "dockerfile": "../docker/cuda_new.Dockerfile" }, "runArgs": [ "--gpus", "device=7" ] }
Make sure to point with the path to the docker file you want to use.
You can than usectrl + shift + p and type Devcontainers: Open Folder in Container and select the folder where you created the subfolder .devcontainer. You will be able to use all the features of VSCode while developing inside the container..
For more details see here.