docker随笔
运行一个mysql docker container
docker run \
--detach \
--name=mysql02 \
--env="MYSQL_ROOT_PASSWORD=root123456@" \
--publish 7306:3306 \
--volume=/root/docker/mysql02/conf.d:/etc/mysql/conf.d \
--volume=/root/docker/mysql02/data:/var/lib/mysql \
mysql/mysql-server:latest \
--character-set-server=utf8 \
--collation-server=utf8_general_ci
更改root外部连接策略(允许外部连接) ,或者是创建一个新的用户
一、修改/etc/mysql/my.conf
找到bind-address = 127.0.0.1这一行
改为bind-address = 0.0.0.0即可,如果是容器挂载文件,需要重启容器才会生效。
二、进入容器修改
docker exec -it mysql02 mysql -uroot -p
use mysql;
update user set host='%' where user='root'
flush privileges;
mongo
docker run \
--detach \
--name=mongo01 \
--publish 27017:27017 \
--volume=/root/docker/mongo01/config:/data/configdb \
--volume=/root/docker/mongo01/db:/data/db/mongo \
mongo
dockerfile: 自己手动发布
#FROM registry.cn-hangzhou.aliyuncs.com/newbe36524
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
COPY . .
ENV ASPNETCORE_URLS http://+:80
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN sed -i 's#http://deb.debian.org#https://mirrors.aliyun.com#g' /etc/apt/sources.list
RUN apt-get update && apt-get install -y vim && apt-get install -y libgdiplus
ENTRYPOINT [ "dotnet", "LighterApi.dll" ]
dockerfile 带项目发布
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster as build
WORKDIR /code
COPY *.csproj /code
RUN dotnet restore
COPY . /code
RUN dotnet publish -c release -o out
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim
WORKDIR /app
COPY --from=build /code/out /app
ENTRYPOINT [ "dotnet", "LighterApi.dll" ]