Docker Install & Usage

Docker Install & Usage

Falling_Sakura HaHa

In ubuntu24.04

Docker Desktop is not supported for ubuntu24.04.

  1. 卸载旧版本
1
2
3
sudo apt-get remove docker \
docker-engine \
docker.io
  1. 更新系统软件包
1
2
sudo apt update
sudo apt upgrade
  1. 安装依赖
1
2
3
4
5
6
7
8
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release \
software-properties-common \
uidmap
  1. 配置软件源
1
2
3
4
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  1. 安装 Docker
1
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

使用 docker --version 验证是否安装成功。

  1. 启动 Docker
1
2
sudo systemctl enable docker
sudo systemctl start docker
  1. 添加用户组
1
2
sudo groupadd docker
sudo usermod -aG docker $USER
  1. 测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:91fb4b041da273d5a3273b6d587d62d518300a6ad268b28628f74997b93171b2
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/
  1. 终端登陆 Dockerhub

先去 Dockerhub 注册一个账号,然后在右上角点击头像,点击 Account Settings,在 Security 中点击 Personal access tokens,然后新建一个 Token,编辑对应名称和权限后,使用它所给出的命令即可。

若出现 Error saving credentials: error storing credentials - err: exec: "docker-credential-desktop": executable file not found in $PATH, out: ``,则编辑 ~/.docker.config.json,把 credsStore 一项删除即可。

  1. 设置开机自启动
1
sudo systemctl enable docker
  1. 检查 Docker 服务状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sudo systemctl status docker

● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled)
Drop-In: /etc/systemd/system/docker.service.d
└─http-proxy.conf
Active: active (running) since Fri 2024-09-13 12:42:41 CST; 41min ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 142120 (dockerd)
Tasks: 20
Memory: 23.8M (peak: 29.9M)
CPU: 788ms
CGroup: /system.slice/docker.service
└─142120 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.s
  1. 配置 rootless(选)

放个官方文档链接

  1. 通过 Github Action 实现 Docker 镜像自动化构建和推送
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: Build and Push Docker Image with Incremental Tagging and Version Bump

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
tags: true

- name: Get the latest Git tag
id: get_tag
run: |
TAG=$(git describe --tags --abbrev=0 || echo "v0.0")
echo "Latest tag: $TAG"
echo "CURRENT_TAG=$TAG" >> $GITHUB_ENV

- name: Calculate new tag with version bump
id: calc_new_tag
run: |
CURRENT_TAG=${{ env.CURRENT_TAG }}
VERSION=$(echo $CURRENT_TAG | sed 's/v//g')
MAJOR=$(echo $VERSION | cut -d. -f1)
MINOR=$(echo $VERSION | cut -d. -f2)

if [ $MINOR -lt 9 ]; then
NEW_MINOR=$((MINOR+1))
NEW_TAG="v$MAJOR.$NEW_MINOR"
else
NEW_MAJOR=$((MAJOR+1))
NEW_MINOR=0
NEW_TAG="v$NEW_MAJOR.$NEW_MINOR"
fi

echo "New tag: $NEW_TAG"
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV

- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and tag Docker image
run: |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/technews-frontend:${{ env.NEW_TAG }} .
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/technews-frontend:${{ env.NEW_TAG }} ${{ secrets.DOCKERHUB_USERNAME }}/technews-frontend:latest

- name: Push Docker image
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/technews-frontend:${{ env.NEW_TAG }}
docker push ${{ secrets.DOCKERHUB_USERNAME }}/technews-frontend:latest

- name: Set up Git credentials
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git

- name: Create new Git tag
run: |
git tag ${{ env.NEW_TAG }}
git push origin ${{ env.NEW_TAG }}
  • Title: Docker Install & Usage
  • Author: Falling_Sakura
  • Created at : 2024-09-13 13:25:59
  • Updated at : 2024-11-21 10:44:39
  • Link: https://vercel.fallingsakura.top/4a7ef8fa.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
On this page
Docker Install & Usage