Skip to content

开发常用

镜像选择

尽量选择 Alpine 版本,体积小,使用apk安装依赖,如 apk add --no-cache gcc g++ python2

如需要python2,尽量使用 alpine 3.14 左右的版本

alpine 设置时区

apk add --no-cache tzdata
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone
可参考dockerfile
dockerfile
# Use the official Alpine image
FROM alpine:latest

# Set the environment variable for the timezone
ENV TZ=UTC
#ENV TZ=Asia/Shanghai

# Install tzdata package for timezone data
RUN apk add --no-cache tzdata

# Set the timezone
RUN cp /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Verify the timezone is set correctly
RUN date

# Your application setup goes here
# ...

# Example entrypoint
CMD ["sh"]

postgres

podman run --rm -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=hello_dev postgres:12.19-alpine

redis

docker run --rm -p 6379:6379 redis

mysql

docker run --rm -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=<default db> -p 3306:3306 mysql

mongodb

docker run --rm -p 27017:27017 mongo

编译设置代理

docker build -t ai:latest . --build-arg HTTP_PROXY=http://<ip>:<port>

映射目录问题(windows环境)

# cmd
docker run --rm -it -v %cd%:/user/src/app gcc
# powershell
docker run --rm -it -v ${PWD}:/user/src/app gcc
# linux
docker run --rm -it -v ${pwd}:/user/src/app gcc
# cross platform
docker run --rm -it -v ${PWD}:/user/src/app gcc
docker run --rm -it -v ${PWD}:/user/src/app gcc