windows 10 安装 Docker Desktop
https://www.docker.com/products/docker-desktop
没有帐号可以新建一下,免费提供一个私有仓库
新建VS 项目
Dockerfile 配置
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base WORKDIR /app EXPOSE 80 COPY . /app ENTRYPOINT ["dotnet", "WebDocker.dll"]
配置好后发布程序
发布成功后,系统会自动推送到仓库中,包括Build命令,VS会替你解决
查看你的镜像
查看本地镜像
Docker images
CentOS 安装 Docker
- 使用
root
权限登录 Centos。确保 yum 包更新到最新。sudo yum update
- 卸载旧版本(如果安装过旧版本的话)
sudo yum remove docker docker-common docker-selinux docker-engine
- 安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
- 设置yum源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- 可以查看所有仓库中所有docker版本,并选择特定版本安装
yum list docker-ce --showduplicates | sort -r
- 安装docker
sudo yum install docker-ce #由于repo中默认只开启stable仓库,故这里安装的是最新稳定版17.12.0
- 启动并加入开机启动
sudo systemctl start docker sudo systemctl enable docker
- 验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
docker version
Docker 安装好 输入docker login
用你刚才注册的用户和密码登录
dokcer images
拉取镜像
docker pull xxx:tag
成功之后运行镜像
docker run -d --restart=always --name myapp -p 5000:80 bch1983410/mydocker :v1
查看运行镜像
docker ps
这时可以访问地址
拉取nginx
docker pull nginx:latest
创建挂载目录
mkdir -p /data/nginx/{conf,conf.d,html,logs}
编写nginx,conf配置文件,并放在文件夹中
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80 default_server; listen [::]:80 default_server; server_name localhost; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_pass http://pic; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } upstream pic{ server localhost:8082 weight=5; } }
启动容器
docker run --name mynginx -d -p 8081:80 -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/logs:/var/log/nginx -d docker.io/nginx
访问地址8081
访问地址8082