• Tutorial
  • Getting started with Docker and NixOS

Getting started with Docker and NixOS

Docker and Nix are available within CodeSandbox Repositories as an experimental feature. You can run and build images to run containers inside your project by opening a terminal and running docker. If you have a docker-compose file in your root folder, you only have to run docker-compose up. Then, all your services will run within CodeSandbox Repositories.

In addition, Nix is also supported. Nix is a tool that takes a unique approach to package management and system configuration. Basically, you can install any additional tool, like Java or Node v16, in your OS.

1. Click on the add a devtool dropdown

Pressing the add devtool button shows a dropdown with the different devtools you can add.

2. Open a new terminal

When selecting the terminal devtool option in the dropdown a sub menu shows up with the option to add a new terminal.

3. Run a docker image

Inside the terminal a command is pasted to run the docker image.

4. Opened ports will be picked up automatically

If you run a development server (for example inside the container) and it opens up a port, then CodeSandbox Repositories will detect that automatically and make the preview available. In this case, you can open the preview from the Other Previews submenu.

DevTools have an option with other previews. Selecting this option will show a submenu with ports running the previews.

5. (Optional) Persist it as a task

If you would like to start a given container every time you create a new branch or even restart your repositories, then you can persist it as a task, as shown below.

When opening the devtools menu and selecting tasks, a submenu with your tasks and an option to add a new task is shown. The new task option is highlighted.

6. Paste in the Command Palette

Simply paste the command into the Command Palette and CodeSandbox Repositories will create a configuration file.

The command palette is shown with an indicator that the current action is adding a task, and the command is pasted inside the input.

7. Put it in the right place in your configuration

If you define this as a task, you will be able to run the container from the UI. You can also put it under setupTask - in this case, the container will start the next time you create a workspace.

Tip: Commit your changes and add the configuration to your repository so CodeSandbox can run the container for every newly created branch.

The tasks.json file is open in the editor and shows all tasks that exist for the project.