# Docker

OnePub is Docker aware and designed to be run in a Docker container as well as on your host.

The are a few issues you need to be aware of when using a local or remote Docker container.

If you are going to use OnePub in your Docker container you will of course need to have Dart installed. You should also install OnePub by adding the following to your Dockerfile:

```docker
RUN dart pub global activate onepub
```

Dart must already have been installed into your Docker container in a prior step  and be on the path.

{% hint style="info" %}
Where possible start with a Docker container that includes Dart such as the [official Dart Docker](https://hub.docker.com/_/dart) container.
{% endhint %}

## onepub login

If you are using the Docker container interactively (e.g. `docker exec -it xxx /bash`) then you can log into OnePub from within the Docker container by running `onepub login`.

If you Docker container runs without user interaction (the normal course of action) then you need to use the `onepub import/export` methods or directly mount the Dart token store.

The same problem will exists in your CI/CD environment (which is usually running in a Docker container).  See the [CI/CD instructions](https://docs.onepub.dev/guides/ci-cd) for additional details pertinent to typical CI/CD environments.

### Use export/import

The simplest method is to use the onepub export/import commands.

{% hint style="info" %}
For additional details on authenticating onepub read the [CI/CD guide](https://docs.onepub.dev/guides/ci-cd)
{% endhint %}

From your desktop CLI run:

> Note: you only need to run onepub login if you are not currently logged in.

```bash
onepub login
onepub export --user <cicd user email>
```

The `onepub export` command will print your OnePub token.&#x20;

**Start an interactive docker session** (e.g. docker exec -it xxxx /bash) and run:

```bash
onepub import --ask
```

When prompted for the ONEPUB\_TOKEN, enter the token displayed when you ran the `onepub export` command.

You are now logged in to OnePub with the Docker session.&#x20;

If your Docker home directory isn't persistent then you will have to re-do the import each time you restart your container.

### Environment variable

The `onepub import` command can also able to take the OnePub token from an environment variable. Refer to the [import](#use-export-import) documentation for details.

### Mount the Dart token store

If your docker container is running on your local PC then you can mount the OnePub and Dart configuration files directly into your docker container.

This will result in the Docker container running with your OnePub account.

For a container running on your local system, the docker `mount bind` option has the advantage that you don't have to log in to your Docker container separately (and each time you rebuild it). Simply log in to onepub on the host and the container will also be logged in.

```
docker exec \
-it \
--mount type=bind,source="/home/me/.config/dart/pub-tokens.json",destination="/home/root/.config/dart/pub-tokens.json" \
--mount type=bind,source="/home/me/.onepub/onepub.yaml",destination="/home/root/.onepub/onepub.yaml" \
dart:latest
```

If you are using VS Code the command :&#x20;

`Remote-Containers: Open Folder in Container...`

then see the [VS Code](https://docs.onepub.dev/guides/installing/ide-integration/visual-studio-code) documentation for details on creating the mounts.

### CI/CD

If your container is running in a CI/CD environment such as a github action then refer to the [CI/CD ](#ci-cd)documentation.

##


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onepub.dev/guides/docker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
