Docker入门笔记

随笔记录初学Docker遇到的问题, 以免下次再犯. 本机系统Ubuntu18.04

安装

Docker有2个版本

  • Community Edition (CE) 社区版(免费)
  • Enterprise Edition (EE) 企业版
  1. 删除旧版

sudo apt-get remove docker docker-engine docker.io

  1. 添加一些依赖包

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

  1. 添加官方GPG Key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

  1. 添加apt私有仓库

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

  1. 安装Docker

sudo apt-get update

sudo apt-get install docker-ce

  1. 检测是否安装

docker --version

创建镜像

  1. 新建dotnet控制台项目

mkdir dotnet-test

cd dotnet-test

dotnet new console

  1. 创建Dockerfile并配置
  # 使用官方dotnet运行时作为父镜像
FROM microsoft/dotnet:latest # 设置工作目录
WORKDIR /app # 拷贝.csproj到工作目录/app,然后执行dotnet restore恢复所有安装的NuGet包
COPY *.csproj ./
RUN dotnet restore # 拷贝所有文件到工作目录(/app), 然后利用dotnet-cli发布应用到/app/out目录下
COPY . ./
RUN dotnet publish -c Release -o out # Docker容器启动时运行
ENTRYPOINT [ "dotnet", "/app/out/dotnet-test.dll" ]
  1. 编译docker镜像

docker build -t dotnet-test .

  1. 查看并运行刚才创建的docker镜像

docker images 可以在输出列表中找到dotnet-test所在行

docker run dotnet-test 运行镜像, docker run命令其实是2条命令(docker create, docker start)结合的快捷方式

搭建私服并上传镜像

  1. 更换镜像源, 换成国内网易的源快一点

sudo vim /etc/default/docker 编辑此配置文件, 输入以下内容(注意换成自己IP)

  # Docker Upstart and SysVinit configuration file

  #
# THIS FILE DOES NOT APPLY TO SYSTEMD
#
# Please see the documentation for "systemd drop-ins":
# https://docs.docker.com/engine/admin/systemd/
# # Customize location of Docker binary (especially for development testing).
#DOCKERD="/usr/local/bin/dockerd" # Use DOCKER_OPTS to modify the daemon startup options.
#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
DOCKER_OPTS="--registry-mirror=http://hub-mirror.c.163.com --add-registry 192.9.1.3:5000 --insecure-registry 192.168.1.3:5000" # If you need Docker to use an HTTP proxy, it can also be specified here.
#export http_proxy="http://127.0.0.1:3128/" # This is also a handy place to tweak where Docker's temporary files go.
#export DOCKER_TMPDIR="/mnt/bigdrive/docker-tmp"
  1. https问题

这个问题可能是由于客户端采用https,docker registry未采用https服务所致。一种处理方式是把客户对地址“192.168.1.3:5000”请求改为http

vim /etc/docker/daemon.json 创建并编辑此文件, 输入内容 {"insecure-registries":["192.168.66.100:5000"]}

  1. 重启docker

sudo service docker restart

  1. 拉取registry镜像, 并启动

docker pull registry 拉取registry镜像

sudo docker run -d -p 5000:5000 -v /home/xueyou/Applications/docker/registry:/var/lib/registry registry 后台启动容器, 要用sudo启动才能有网络权限

  1. 上传镜像到私服

docker tag dotnet-test:latest 192.168.1.3:5000/dotnet-test 标记镜像, 将本地镜像和远程私服关联

docker push 192.168.1.3:5000/dotnet-test 镜像上传到私服

docker rmi 192.168.1.3:5000/dotnet-test 删除本地镜像

docker pull 192.168.1.3:5000/dotnet-test 从私服下载镜像

Tips

  • 有时候registry容器删不掉可以执行 sudo killall docker-containerd-shim 然后docker重新运行容器

Docker入门笔记的更多相关文章

  1. Docker入门笔记(1)

    Docker入门笔记(1) 1.安装Docker yum -y install docker-ce 2.查看Docker版本 [root@localhost ~]# docker -v Docker ...

  2. Centos7——docker入门(笔记)

    docker 入门(笔记) 一.Docker是什么? 官方原话: Docker provides a way to run applications securely isolated in a co ...

  3. Docker入门-笔记-1

    Docker入门 Docker 是 Golang 编写的, 自 2013 年推出以来,受到越来越多的开发者的关注.如果你关注最新的技术发展,那么你一定听说过 Docker.不管是云服务还是微服务(Mi ...

  4. Docker 入门笔记

    Docker 可以理解为一个轻量化的虚拟机, 启动速度快,本身占的资源小 [重要], 容器里是不能保存数据的,容器只要一停止, 所有的数据都会丢失,所以如果重要的数据, 都需要通过配制,把数据保存在 ...

  5. 笔记 docker入门笔记

    安装sudo apt-get remove docker docker-engine docker-ce docker.iosudo apt-get updatesudo apt-get instal ...

  6. Docker入门笔记(Centos7)

    centos7 wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo vim docker-c ...

  7. docker入门与部署微服务--学习笔记

    最近公司进一步去windows,走向 linux+云化. 原来的一大坨windows虚拟机服务器都要转向linux, 既然走向linux的话,那么docker肯定是要涉足的. 故学习了docker入门 ...

  8. docker学习笔记1 -- 安装和配置

    技术资料 docker中文官网:http://www.docker.org.cn/ 中文入门课程:http://www.docker.org.cn/book/docker.html docker学习笔 ...

  9. Docker入门命令

    Edit Docker入门命令 # 安装镜像sudo docker pull ubuntu:12.04# 镜像列表sudo docker images# 运行镜像sudo docker run -t ...

随机推荐

  1. [Swift]LeetCode462. 最少移动次数使数组元素相等 II | Minimum Moves to Equal Array Elements II

    Given a non-empty integer array, find the minimum number of moves required to make all array element ...

  2. [Swift]LeetCode794. 有效的井字游戏 | Valid Tic-Tac-Toe State

    A Tic-Tac-Toe board is given as a string array board. Return True if and only if it is possible to r ...

  3. [Swift]LeetCode1012. 至少有 1 位重复的数字 | Numbers With 1 Repeated Digit

    Given a positive integer N, return the number of positive integers less than or equal to N that have ...

  4. MySQL 规范及优化

    一.建库建表优化 1.核心规范(推荐) 表字符集选择UTF8 (“表情”字段单独设置为其他字符集) 存储引擎使用INNODB 不在库中存储图片.文件等 使用可变长字符串(varchar) 每张表数据量 ...

  5. 使用ML.NET实现白葡萄酒品质预测

    导读:ML.NET系列文章 本文将基于ML.NET v0.2预览版,介绍机器学习中的分类和回归两个重要概念,并实现白葡萄酒品质预测. 本系列前面的文章也提到了一些,经典的机器学习最主要的特点就是模拟, ...

  6. 学习springboot

    一般而言,写个Javaweb应用搭建环境都可能要几十分钟,下载个tomcat服务器,再加上各种xml配置等等,很烦躁,而且每个web应用的配置还差不多,都是什么web.xml,application. ...

  7. 基于spark实现并行化Apriori算法

    详细代码我已上传到github:click me 一. 实验要求         在 Spark2.3 平台上实现 Apriori 频繁项集挖掘的并行化算法.要求程序利用 Spark 进行并行计算. ...

  8. MySQL ProxySQL相关维护说明

    背景: 前面的2篇文章MySQL ProxySQL读写分离使用初探和MySQL ProxySQL读写分离实践大致介绍了ProxySQL的使用说明,从文章的测试的例子中看到ProxySQL使用SQLIT ...

  9. 第27章 联合网关 - Identity Server 4 中文文档(v1.0.0)

    通用架构是所谓的联合网关.在此方法中,IdentityServer充当一个或多个外部身份提供商的网关. 该架构具有以下优点: 您的应用程序只需要了解一个令牌服务(网关),并且屏蔽了有关连接到外部提供程 ...

  10. .Net Excel 导出图表Demo(柱状图,多标签页)

    1 使用插件名称Epplus,多个Sheet页数据应用,Demo为柱状图(Epplus支持多种图表) 2 Epplus 的安装和引用 新建一个工程文件或控制台应用程序 打开 Vs2017 Tools  ...