本文介绍: 【代码】Docker快速入门(编译源码辅助技)

什么是docker(⭐⭐⭐)
https://www.cnblogs.com/Can-daydayup/p/15559341.html

安装WSL官方教程(⭐⭐⭐⭐)
https://codefellows.github.io/setup-guide/system-setup/windows/windows-10.html

点灯(⭐⭐⭐⭐)
https://blog.csdn.net/m0_63834988/article/details/131816239

Docker工具箱(⭐⭐⭐⭐)
https://blog.csdn.net/appke846/article/details/80534782

镜像 搜索(⭐⭐)
Ctrl + K or https://hub.docker.com/_/ubuntu/tags?page=1&name=20.

DockerFile操作(⭐)
https://yeasy.gitbook.io/docker_practice/image/build

操作集

docker pull ubutun:20.04 #下载镜像
docker images   #查询镜像
docker rmi <your-image-id>#删除镜像

#启动镜像生成容器
docker run -it <REPOSITORY:TAG> /bin/bash   # 使用  仓库名+标签 启动
docker run -it <IMAGE ID> /bin/bash     # 使用 IMAGE ID 启动
docker run -it --name Qm 83a4bf3bb050 /bin/bash#  # 使用 IMAGE + TAG 启动 带别名

#启动容器 
docker exec -it <CONTAINER ID>  /bin/bash # 链接到容器,并获取一个伪终端⭐

docker start <CONTAINER ID> /bin/bash # 使用 CONTAINER ID 启动⭐⭐⭐⭐
docker stop  <CONTAINER ID>  # 停止
docker attach <NAME or CONTAINER ID> #进入容器  CONTAINER ID 或者 NAME 

docker ps     #查看正在运行的容器
docker ps -a  #查看所有容器
docker ps -l  #查看最近一次运行的容器

docker rm $(docker ps -a -q) #删除所有容器
docker rm <CONTAINER ID> #删除容器

docker top 	   #容器名   查看WEB应用程序容器的进程
docker inspect #容器名 	查看Docker的底层信息

to be continue...		#上传镜像

导入&导出镜像

maqi@05878mq:~$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
maqi@05878mq:~$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS                        PORTS     NAMES
1e7184d214b9   ubuntu:20.04   "/bin/bash"   35 minutes ago   Exited (130) 19 minutes ago             Qm
maqi@05878mq:~$ docker export 1e7184d214b9 >Qm.tar
maqi@05878mq:~$ ls
Qm.tar
maqi@05878mq:~$ docker import - qQm < Qm.tar
invalid reference format: repository name must be lowercase
maqi@05878mq:~$ docker import - qqm < Qm.tar
sha256:9cf697b9d73dc64f7cc007b76f67ca11de6181fff150c3edd7afe8c707952395
maqi@05878mq:~$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS                        PORTS     NAMES
1e7184d214b9   ubuntu:20.04   "/bin/bash"   38 minutes ago   Exited (130) 22 minutes ago             Qm
maqi@05878mq:~$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
qqm          latest    9cf697b9d73d   23 seconds ago   72.8MB
ubuntu       20.04     83a4bf3bb050   8 days ago       72.8MB

下载vim

mv /etc/apt/sources.list /etc/apt/sources.list.bak

cat <<EOF >/etc/apt/sources.list
deb http://mirrors.ustc.edu.cn/debian stable main contrib non-free
deb http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free
EOF

apt update

apt install vim

mv /etc/apt/sources.list.bak /etc/apt/sources.list

换源
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

#查看版本
lsb_release-a
#安装https证书
apt install apt-transport-https ca-certificates
#更新源 
apt-get update 
#下载sudo
apt-get install sudo

Avoiding user interaction with tzdata when installing certbot in a docker container
DEBIAN_FRONTEND=noninteractive

文件拷贝

容器 ☞ Wind10

maqi@05878mq:/$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS          PORTS     NAMES
ce0cf467cb65   39b4e9567be4   "/bin/bash"   40 minutes ago   Up 17 minutes             launcher3
maqi@05878mq:/$ docker cp ce0cf467cb65:test.txt /mnt/f/share
Successfully copied 2.05kB to /mnt/f/share

容器 ☞ 宿主机
同上

root@05878mq:~# docker cp ce0cf467cb65:test.txt /home/maqi/test1.txt
Successfully copied 2.05kB to /home/maqi/test1.txt
root@05878mq:~# cd /home/maqi/
.aws/                      .bashrc                    .motd_shown                launcher3.tar
.azure/                    .cache/                    .profile                   test1.txt
.bash_history              .config/                   .sudo_as_admin_successful
.bash_logout               .docker/                   .viminfo
root@05878mq:~# cd /home/maqi/
root@05878mq:/home/maqi# ls -l
total 1255976
-rwxrwxrwx 1 maqi maqi 1286107648 Dec  7 15:01 launcher3.tar
-rwxrwxrwx 1 root root        157 Dec  7 15:43 test1.txt
root@05878mq:/home/maqi# vim test1.txt 

Wind10☞ 容器
暂无

宿主机☞容器

maqi@05878mq:/$ sudo chmod 777 suzhu.txt
maqi@05878mq:/$ docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS          PORTS     NAMES
ce0cf467cb65   39b4e9567be4   "/bin/bash"   48 minutes ago   Up 24 minutes             launcher3
maqi@05878mq:/$ docker cp suzhu.txt ce0cf467cb65:/
Successfully copied 1.54kB to ce0cf467cb65:/

宿主机☞ Wind10
宿主机默认挂载

maqi@05878mq:/$ cd mnt/
maqi@05878mq:/mnt$ ls-l
ls-l: command not found
maqi@05878mq:/mnt$ ls -l
total 0
drwxrwxrwx 1 maqi maqi 4096 Dec  7 08:51 c
drwxrwxrwx 1 maqi maqi  512 Dec  7 15:25 d
drwxrwxrwx 1 maqi maqi  512 Dec  7 08:51 e
drwxrwxrwx 1 maqi maqi  512 Dec  7 15:47 f
drwxrwxrwt 5 root root  120 Dec  7 10:10 wsl
drwxrwxrwt 8 root root  320 Dec  7 10:09 wslg

端口管理
to be continue...

下节我将引入docker编译Android源码的章节
想象一下如果我们有一个可以随拿随走的编译环境,不像VM那样复制一份虚拟机,还存在硬件兼容的风险。大大加快了我们的学习速度,是不是想想都有点小激动 🤩🤩🤩🤩

原文地址:https://blog.csdn.net/qq_20330595/article/details/134799908

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_50719.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注