Skip to content
An`s Weblog
Go back

Distributing Images on Docker Hub

Mục tiêu bài học:

Quy trình các bước

1. Tạo tài khoản Docker Hub

- Truy cập: [https://hub.docker.com](https://hub.docker.com/)
- Đăng ký tài khoản và đăng nhập.

2. Tạo Dockerfile mới

```bash
cd docker_images/
mkdir dockerhub
cd dockerhub
vi Dockerfile

```

Paste nội dung Dockerfile từ bài Multi-Stage Builds.

3. Clone source code

```bash
git clone https://github.com/linuxacademy/weather-app.git
cd weather-app/src
git log -1 --pretty=%h   # lấy commit hash
cd ../..   # về lại thư mục gốc

```

4. Build image

```bash
docker image build -t linuxacademy/weather-app:<commit-hash> --build-arg VERSION=1.5 .

```

5. Tag image chuẩn bị đẩy lên Docker Hub

```bash
docker image tag linuxacademy/weather-app:<commit-hash> <dockerhub-username>/weather-app:<commit-hash>

```

6. Push lên Docker Hub

```bash
docker login   # nếu chưa đăng nhập
docker image push <dockerhub-username>/weather-app:<commit-hash>

```

7. Tạo thêm tag latest cho cùng image

```bash
docker image tag <dockerhub-username>/weather-app:<commit-hash> <dockerhub-username>/weather-app:latest
docker image push <dockerhub-username>/weather-app:latest

```

Kết quả trên Docker Hub

Tổng kết lệnh

LệnhMục đích
docker loginĐăng nhập Docker Hub
docker image buildBuild image từ Dockerfile
docker image tagGán thêm tag mới cho image
docker image pushPush image lên Docker Hub

Share this post:

Previous Post
Image History
Next Post
Tagging