docker学习笔记

1. Vmware搭建ubuntu环境

(1)Vmware下载

        下载地址:非商用版本

(2) 遇见的问题汇总

问题1:如何将英文系统修改成中文系统?

        参考链接:ubuntu设置系统语言为中文

问题2:如何将中文默认文件名重新修改为英文?   

       若在修改中文系统时将默认文件名改为中文吗,则在终端中执行以下命令,然后重启系统。 

export LANG=en_US
xdg-user-dirs-gtk-update
export LANG=zh_CN.UTF-8

 问题3:如何安装中文输入法?

       输入法下载:搜狗输入法

       安装过程:参考链接

 问题4:如何在右键中增加新建文件?

         参考链接:ubuntu桌面模式下,鼠标右键没有新建文档的解决方法

 问题5:如何安装sublime text?

        软件下载:地址 

        执行安装命令:

sudo dpkg -i sublime-text_build-3211_amd64.deb

2. docker环境搭建

        参考文献:地址 

(1) docker安装

  •         安装命令
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

        注:若报如下错误,

         则按照以下命名将webupd8team/sublime-text-3这个PPA文件删除

sudo add-apt-repository --remove ppa:/webupd8team/sublime-text-3

         参考链接:地址

  • 验证是否安装成功 
sudo docker run hello-world

         结果:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:e86134b19508866f9a94095ebed0cc4322d1340f1855f52057a748ca06880720
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

3.docker容器和镜像的关系

        参考文献:地址

        容器是由镜像实例化而来,这和我们学习的面向对象的概念十分相似,我们可以把镜像看作类,把容器看作类实例化后的对象。若需要运行一个镜像,需要创建该镜像的运行实例即镜像,多个镜像是互不干扰的。

4. docker容器的常用命令

(1)查看本机容器

sudo docker ps [-a]

        默认参数查看的是正在运行的容器

(2)运行容器

sudo docker run -itd --name test python:3.6 /bin/bash

-i:交互式        -t:终端(命令行,shell,因此后面使用/bin/bash)        --name:指定容器名称

(3)停止全部容器

sudo docker rm $(sudo docker ps -aq)

         -q只显示id

(4)导入、导出容器快照,生成镜像文件

sudo docker export <container id> > <file_path> //导出容器快照
sudo docker import <file_path> <image_name>:<image_tag> //导入容器快照为镜像

(5)构建镜像

sudo docker build -t <image_name>:<image_tag> .

        “.”表示当前目录,即Dockerfile所在目录

(6)新建Dockerfile,构建python3.6+opencv镜像

# 基础镜像
FROM python:3.6
# 修改pip的源(非必要)
COPY ./pip ~/.config
# 拷贝python版本的opencv文件到镜像中
COPY opencv_python-4.5.3.56-cp36-cp36m-manylinux2014_x86_64.whl .
# 为解决导入opencv时的报错ImportError: libGL.so.1: cannot open shared object file: No such
# file or directory,执行已下命令
RUN apt-get update \
	&& apt-get install libgl1-mesa-glx -y
# pip安装opencv
RUN pip install opencv_python-4.5.3.56-cp36-cp36m-manylinux2014_x86_64.whl --user \
	&& rm opencv_python-4.5.3.56-cp36-cp36m-manylinux2014_x86_64.whl
# 切换工作目录
WORKDIR .

5.其他

(1)阿里云镜像加速

参考链接:地址

(2)搭建本地docker资源库

参考链接:地址 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值