Upload images to a Docker repository
This article refers to Platform v3.1.0. The current Platform version is v3.2.0.
Overview
To share a Docker image — including with a Barbara edge node that needs to pull it — you push it to a registry. The most common public registry is Docker Hub, but the same workflow applies to private registries (Amazon ECR, Google GCR, Harbor, etc.). This article walks you through tagging, logging in, and pushing an image, with a quick Node.js example.
Watch this step on YouTube: Uploading Images to Docker Repositories.
What is a Docker repository?
A registry is the service that stores Docker images. A repository inside a registry is a named bucket that holds multiple tagged versions of the same image (my-app:1.0, my-app:2.0, my-app:latest). Registries can be public (Docker Hub) or private.
The lifecycle of an image is straightforward:
- Build — produce the image from a Dockerfile.
- Tag — rename the image with the form
<registry>/<repository>:<tag>. - Push — upload the tagged image to the registry.
From there, anyone (or any node) with read access can docker pull it and run it.
Prerequisites
- Docker installed on your laptop.
- A free Docker Hub account — sign up at hub.docker.com.
Practice — build, tag, and push to Docker Hub
1. Create the project
mkdir 05_docker-repository
cd 05_docker-repository
app.js:
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello, Docker Hub!\n');
});
server.listen(8080, () => {
console.log('Server running on http://localhost:8080');
});
package.json:
{
"name": "docker-repository",
"version": "1.0.0",
"main": "app.js",
"dependencies": {
"http": "^0.0.1-security"
}
}
Dockerfile:
FROM node:14
WORKDIR /app
COPY package*.json ./
COPY app.js ./
RUN npm install
EXPOSE 8080
CMD ["node", "app.js"]
2. Build the image
docker build -t docker-repo-practice:1.0 .
3. Tag the image for Docker Hub
Tags pushed to Docker Hub must be prefixed with your username:
docker tag docker-repo-practice:1.0 <your-docker-hub-username>/docker-repo-practice:1.0
4. Log in to Docker Hub
docker login
Enter your Docker Hub username and password when prompted.
5. Push
docker push <your-docker-hub-username>/docker-repo-practice:1.0
6. Verify on Docker Hub
Log into hub.docker.com and check the docker-repo-practice repository under your account. The 1.0 tag should be there.
7. Run from the registry
Anyone — including your laptop — can now pull and run it:
docker run -p 8080:8080 <your-docker-hub-username>/docker-repo-practice:1.0
Open http://localhost:8080 and you should see Hello, Docker Hub!.
Summary
Pushing an image to a registry is what turns it into a deployable artefact — Docker Hub for public images, private registries for everything else. From a Barbara edge node, the registry credentials live in the Docker Credentials card, and the pull happens automatically when you install the app.