Build/Publish Docker Image
Build a Docker image in a OneDev job and publish it to Docker Hub. This example packages a small static website with Nginx; replace the website build step with your application's build and tests as needed.
Prepare the Repository
Add an index.html file:
<!doctype html>
<title>OneDev tutorial</title>
<h1>Built by OneDev</h1>
Add a Dockerfile at the repository root:
FROM nginx:alpine
COPY dist/ /usr/share/nginx/html/
The job below creates dist/index.html before building this image.
Configure the Job
Create or edit .onedev-buildspec.yml, add a job, and configure these steps in order:
-
Checkout Code: leave the default clone credential selected.
-
Execute Commands: enable Run In Container, use image
alpine:3.22, choose POSIX Compatible Shell with shellsh, and enter:mkdir -p distcp index.html dist/test -s dist/index.html -
Docker Image / Build Image: leave Build Path and Dockerfile empty to use the working directory and its
Dockerfile. Choose Push to container registry for Output, and set Tags toYOUR_ACCOUNT/YOUR_REPOSITORY:@build_number@. Replace the account and repository with a Docker Hub repository you can push to.
Leave each step's Condition as Successful so a failed build prevents publication.
Configure Registry Access and Execution
The image build step requires a Server Docker Executor or Remote Docker Executor, with Docker and Buildx available on its host. Configure executors under Administration / Job Executors. If Job Executor is left unspecified, OneDev selects an applicable executor; when none is configured, it attempts auto-discovery.
The Docker process used by that executor must be authenticated to Docker Hub. You can use an existing login on the executor host. Alternatively, store a Docker Hub token as a job secret, then add a login under the image step's More Settings / Registry Logins: leave Registry URL empty for Docker Hub, enter the Docker Hub username, and select the secret as Password Secret. Registry logins can also be configured on the executor.
Run and Verify
Commit the build specification and run the job. Check that checkout, application build, and image publication all succeed. The image tag is the OneDev build number.
From a machine with Docker, verify the published image, replacing the account, repository, and build number:
docker pull YOUR_ACCOUNT/YOUR_REPOSITORY:1
docker run --rm YOUR_ACCOUNT/YOUR_REPOSITORY:1 cat /usr/share/nginx/html/index.html
The output should contain Built by OneDev.