构建镜像
- 编写Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| FROM python:3.9-slim
WORKDIR /app
COPY . /app
# 安装依赖
RUN pip install --no-cache-dir flask requests
# 暴露应用运行的端口
EXPOSE 5000
# 运行 Flask 应用
CMD ["python", "pgsh_server.py"]
|
非常的简单,是一个python的flask应用。
- 构建
1
| docker build -t get-pgsh-token:1.0 .
|
如果构建的时候镜像拉不下了的话可以先pull一下再构建。
- 运行测试
1
| docker run -d -p 5000:5000 get-pgsh-token:1.0
|
上传镜像
- 打标签
1
| docker tag get-pgsh-token:1.0 masterke2003/get-pgsh-token:1.0
|
- 登录DockerHub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| [root@rhel9 pgsh]# docker login
USING WEB-BASED LOGIN
To sign in with credentials on the command line, use 'docker login -u <username>'
Your one-time device confirmation code is: BDQV-GPMJ
Press ENTER to open your browser or submit your device code here: https://login.docker.com/activate
Waiting for authentication in the browser…
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credential-stores
Login Succeeded
|
- 上传
1
| docker push masterke2003/get-pgsh-token:1.0
|
DockerHub验证
可以看到已经push成功了,后面可以直接在任意一台机器使用docker run -d -p 5000:5000 get-pgsh-token:1.0
进行运行容器。