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:
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.
Where possible start with a Docker container that includes Dart such as the official Dart Docker container.
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
If you Docker container runs without user interaction (the normal course of action) then you need to use the
onepub import/exportmethods 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 for additional details pertinent to typical CI/CD environments.
The simplest method is to use the onepub export/import commands.
Form additional details on authenticating onepub read the CI/CD guide
From your desktop CLI run:
Note: you only need to run onepub login if you are not currently logged in.
onepub exportcommand will print your OnePub token.
Start an interactive docker session (e.g. docker exec -it xxxx /bash) and run:
onepub import --ask
When prompted for the ONEPUB_TOKEN, enter the token displayed when you ran the
You are now logged in to OnePub with the Docker session.
If your Docker home directory isn't persistent then you will have to re-do the import each time you restart your container.
onepub importcommand can also able to take the OnePub token from an environment variable. Refer to the import documentation for details.
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 bindoption 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 \
--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" \
If you are using the vscode the command :
Remote-Containers: Open Folder in Container...
If you container is running in a CI/CD environment such as a github action then refer to the CI/CD documentation.