forked from NJU-ProjectN/ics-pa-gitbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0.1.html
1039 lines (510 loc) · 41.3 KB
/
0.1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Installing a GNU/Linux VM · GitBook</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="gitbook/style.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-page-footer-ex/style/plugin.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-callouts/plugin.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="styles.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="0.2.html" />
<link rel="prev" href="PA0.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="./">
<a href="./">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="PA0.html">
<a href="PA0.html">
PA0 - 世界诞生的前夜: 开发环境配置
</a>
<ul class="articles">
<li class="chapter active" data-level="1.2.1" data-path="0.1.html">
<a href="0.1.html">
Installing a GNU/Linux VM
</a>
</li>
<li class="chapter " data-level="1.2.2" data-path="0.2.html">
<a href="0.2.html">
First Exploration with GNU/Linux
</a>
</li>
<li class="chapter " data-level="1.2.3" data-path="0.3.html">
<a href="0.3.html">
Installing Tools
</a>
</li>
<li class="chapter " data-level="1.2.4" data-path="0.4.html">
<a href="0.4.html">
Configuring vim
</a>
</li>
<li class="chapter " data-level="1.2.5" data-path="0.5.html">
<a href="0.5.html">
More Exploration
</a>
</li>
<li class="chapter " data-level="1.2.6" data-path="0.6.html">
<a href="0.6.html">
Transferring Files between host and container
</a>
</li>
<li class="chapter " data-level="1.2.7" data-path="0.7.html">
<a href="0.7.html">
Acquiring Source Code for PAs
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.3" data-path="PA1.html">
<a href="PA1.html">
PA1 - 开天辟地的篇章: 最简单的计算机
</a>
<ul class="articles">
<li class="chapter " data-level="1.3.1" data-path="1.1.html">
<a href="1.1.html">
在开始愉快的PA之旅之前
</a>
</li>
<li class="chapter " data-level="1.3.2" data-path="1.2.html">
<a href="1.2.html">
开天辟地的篇章
</a>
</li>
<li class="chapter " data-level="1.3.3" data-path="1.3.html">
<a href="1.3.html">
RTFSC
</a>
</li>
<li class="chapter " data-level="1.3.4" data-path="1.4.html">
<a href="1.4.html">
基础设施
</a>
</li>
<li class="chapter " data-level="1.3.5" data-path="1.5.html">
<a href="1.5.html">
表达式求值
</a>
</li>
<li class="chapter " data-level="1.3.6" data-path="1.6.html">
<a href="1.6.html">
监视点
</a>
</li>
<li class="chapter " data-level="1.3.7" data-path="1.7.html">
<a href="1.7.html">
i386手册
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.4" data-path="PA2.html">
<a href="PA2.html">
PA2 - 简单复杂的机器: 冯诺依曼计算机系统
</a>
<ul class="articles">
<li class="chapter " data-level="1.4.1" data-path="2.1.html">
<a href="2.1.html">
不停计算的机器
</a>
</li>
<li class="chapter " data-level="1.4.2" data-path="2.2.html">
<a href="2.2.html">
RTFSC(2)
</a>
</li>
<li class="chapter " data-level="1.4.3" data-path="2.3.html">
<a href="2.3.html">
程序, 运行时环境与AM
</a>
</li>
<li class="chapter " data-level="1.4.4" data-path="2.4.html">
<a href="2.4.html">
基础设施(2)
</a>
</li>
<li class="chapter " data-level="1.4.5" data-path="2.5.html">
<a href="2.5.html">
输入输出
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.5" data-path="PA3.html">
<a href="PA3.html">
PA3 - 穿越时空的旅程: 批处理系统
</a>
<ul class="articles">
<li class="chapter " data-level="1.5.1" data-path="3.1.html">
<a href="3.1.html">
最简单的操作系统
</a>
</li>
<li class="chapter " data-level="1.5.2" data-path="3.2.html">
<a href="3.2.html">
穿越时空的旅程
</a>
</li>
<li class="chapter " data-level="1.5.3" data-path="3.3.html">
<a href="3.3.html">
用户程序和系统调用
</a>
</li>
<li class="chapter " data-level="1.5.4" data-path="3.4.html">
<a href="3.4.html">
文件系统
</a>
</li>
<li class="chapter " data-level="1.5.5" data-path="3.5.html">
<a href="3.5.html">
批处理系统
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.6" data-path="PA4.html">
<a href="PA4.html">
PA4 - 虚实交错的魔法: 分时多任务
</a>
<ul class="articles">
<li class="chapter " data-level="1.6.1" data-path="4.1.html">
<a href="4.1.html">
多道程序
</a>
</li>
<li class="chapter " data-level="1.6.2" data-path="4.2.html">
<a href="4.2.html">
虚实交错的魔法
</a>
</li>
<li class="chapter " data-level="1.6.3" data-path="4.3.html">
<a href="4.3.html">
超越容量的界限
</a>
</li>
<li class="chapter " data-level="1.6.4" data-path="4.4.html">
<a href="4.4.html">
来自外部的声音
</a>
</li>
<li class="chapter " data-level="1.6.5" data-path="4.5.html">
<a href="4.5.html">
编写不朽的传奇
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.7" data-path="PA5.html">
<a href="PA5.html">
PA5 - 天下武功唯快不破: 程序与性能
</a>
<ul class="articles">
<li class="chapter " data-level="1.7.1" data-path="5.1.html">
<a href="5.1.html">
浮点数的支持
</a>
</li>
<li class="chapter " data-level="1.7.2" data-path="5.2.html">
<a href="5.2.html">
通往高速的次元
</a>
</li>
<li class="chapter " data-level="1.7.3" data-path="5.3.html">
<a href="5.3.html">
天下武功唯快不破
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.8" data-path="blank.html">
<a href="blank.html">
杂项
</a>
<ul class="articles">
<li class="chapter " data-level="1.8.1" data-path="why.html">
<a href="why.html">
为什么要学习计算机系统基础
</a>
</li>
<li class="chapter " data-level="1.8.2" data-path="submit.html">
<a href="submit.html">
实验提交要求
</a>
</li>
<li class="chapter " data-level="1.8.3" data-path="linux.html">
<a href="linux.html">
Linux入门教程
</a>
</li>
<li class="chapter " data-level="1.8.4" data-path="man.html">
<a href="man.html">
man入门教程
</a>
</li>
<li class="chapter " data-level="1.8.5" data-path="git.html">
<a href="git.html">
git入门教程
</a>
</li>
<li class="chapter " data-level="1.8.6" data-path="i386-intro.html">
<a href="i386-intro.html">
i386手册指令集阅读指南
</a>
</li>
<li class="chapter " data-level="1.8.7" data-path="exec.html">
<a href="exec.html">
指令执行例子
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="." >Installing a GNU/Linux VM</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<p>PA0 is a guide to GNU/Linux development environment configuration.
You are guided to install a GNU/Linux development environment.
All PAs and Labs are done in this environment.
<font color="red">If you are new to GNU/Linux, and you encounter some troubles during the configuration,
which are not mentioned in this lecture note (such as "No such file or directory"), that is your fault.</font>
Go back to read this lecture note carefully.
<font color="red">Remember, the machine is always right!</font></p>
<!-- -->
<div class="panel panel-success"><div class="panel-heading"><h5 class="panel-title" id="信息框说明"><i class="fa fa-lightbulb-o"></i> 信息框说明</h5></div><div class="panel-body"><p>讲义中会出现一些信息框, 根据其颜色和左上角的图标可以得知信息的类别.
例如本信息框就是一些提示相关的内容. 其它类别主要还有</p><div class="panel panel-success"><div class="panel-heading"><h5 class="panel-title" id="实验进度相关的提示"><i class="fa fa-flag"></i> 实验进度相关的提示</h5></div><div class="panel-body"></div></div><div class="panel panel-info"><div class="panel-heading"><h5 class="panel-title" id="扩展阅读"><i class="fa fa-comment-o"></i> 扩展阅读</h5></div><div class="panel-body"></div></div><div class="panel panel-info"><div class="panel-heading"><h5 class="panel-title" id="选做思考题"><i class="fa fa-question-circle"></i> 选做思考题</h5></div><div class="panel-body"></div></div><div class="panel panel-warning"><div class="panel-heading"><h5 class="panel-title" id="实验必做内容"><i class="fa fa-edit"></i> 实验必做内容</h5></div><div class="panel-body"></div></div><div class="panel panel-danger"><div class="panel-heading"><h5 class="panel-title" id="实验进度相关的必读信息"><i class="fa fa-exclamation"></i> 实验进度相关的必读信息</h5></div><div class="panel-body"></div></div><div class="panel panel-danger"><div class="panel-heading"><h5 class="panel-title" id="重要性超越实验的原则与方法"><i class="fa fa-bullhorn"></i> 重要性超越实验的原则与方法</h5></div><div class="panel-body"></div></div></div></div>
<!-- -->
<div class="panel panel-danger"><div class="panel-heading"><h5 class="panel-title" id="对-你没有看错-除了一些重要的信息之外-pa0的实验讲义都是英文"><i class="fa fa-bullhorn"></i> 对, 你没有看错, 除了一些重要的信息之外, PA0的实验讲义都是英文!</h5></div><div class="panel-body"><p>随着科学技术的发展, 在国际学术交流中使用英语已经成为常态:
顶尖的论文无一不使用英文来书写, 在国际上公认的计算机领域经典书籍也是使用英文编著.
顶尖的论文没有中文翻译版; 如果需要获取信息, 也应该主动去阅读英文材料, 而不是等翻译版出版.
"我是中国人, 我只看中文"这类观点已经不符合时代发展的潮流,
要站在时代的最前沿, 阅读英文材料的能力是不可或缺的.</p><p>阅读英文材料, 无非就是"不会的单词查字典, 不懂的句子反复读".
如今网上有各种词霸可解燃眉之急, 但英文阅读能力的提高贵在坚持.
"刚开始觉得阅读英文效率低", 是所有中国人都无法避免的经历.
如果你发现身边的大神可以很轻松地阅读英文材料, 那是因为他们早就克服了这些困难.
引用陈道蓄老师的话: 坚持一年, 你就会发现有不同; 坚持两年, 你就会发现大有不同.</p><p>撇开这些高大上的话题不说, 阅读英文材料和你有什么关系呢?
有! 因为在PA中陪伴你的, 就是没有中文版的<a href="http://microsym.com/editor/assets/386intel.pdf" target="_blank">i386手册</a>,
当然还有<code>man</code>: 如果你不愿意阅读英文材料, 你是注定无法独立完成PA的.</p><p>作为过渡, 我们为大家准备了全英文的PA0.
PA0的目的是配置实验环境, 同时熟悉GNU/Linux下的工作方式.
其中涉及的都是一些操作性的步骤, 你不必为了完成PA0而思考深奥的问题.</p><p><font color="red">你需要独立完成PA0, 请你认真阅读讲义中的每一个字符, 并按照讲义中的内容进行操作:
当讲义提到要在互联网上搜索某个内容时, 你就去互联网上搜索这个内容.
如果遇到了错误, 请认真反复阅读讲义内容, <u>机器永远是对的</u>.</font>
如果你是第一次使用GNU/Linux, 你还需要查阅大量资料或教程来学习一些新工具的使用方法,
这需要花费大量的时间(例如你可能需要花费一个下午的时间, 仅仅是为了使用<code>vim</code>在文件中键入两行内容).
这就像阅读英文材料一样, 一开始你会觉得效率很低, 但随着时间的推移, 你对这些工具的使用会越来越熟练.
相反, 如果你通过"投机取巧"的方式来完成PA0, 你将会马上在PA1中遇到麻烦.
正如etone所说, 你在专业上的技不如人, 迟早有一天会找上来.</p><p>另外, PA0的讲义只负责给出操作过程, 并不负责解释这些操作相关的细节和原理.
如果你希望了解它们, 请在互联网上搜索相关内容.</p></div></div>
<h2 id="installing-docker">Installing Docker</h2>
<p><a href="https://www.docker.com" target="_blank">Docker</a> is an implementation of the lightweight virtualization technology.
Virtual machines built by this technology is called "container".
By using Docker, it is very easy to deploy GNU/Linux applications.</p>
<p>If you already have one copy of GNU/Linux distribution different from which we recommend,
and you want to use your copy as the development environment,
we still encourage you to install docker on your GNU/Linux distribution
to use the same GNU/Linux distribution we recommend over docker
to avoid issues brought by platform disparity.
Refer to <a href="https://docs.docker.com" target="_blank">Docker online Document</a> for more information about installing Docker for GNU/Linux.
It is OK if you still insist on your GNU/Linux distribution.
But if you encounter some troubles because of platform disparity,
please search the Internet for trouble-shooting.</p>
<p>It is also OK to use traditional virtual machines, such as VMWare or VirtualBox, instead of Docker.
If you decide to do this and you do not have a copy of GNU/Linux,
please install <a href="http://www.debian.org" target="_blank">Debian 9</a> distribution in the virtual machine.
Also, please search the Internet for trouble-shooting if you have any problems about virtual machines.</p>
<div class="panel panel-danger"><div class="panel-heading"><h5 class="panel-title" id="必须使用64位的gnulinux"><i class="fa fa-exclamation"></i> 必须使用64位的GNU/Linux</h5></div><div class="panel-body"><p>如果你打算使用已有的GNU/Linux平台, 请确保它是64位版本.
今年PA的新增特性会依赖于64位平台.</p></div></div>
<p>Download Docker from <a href="https://www.docker.com/community-edition#/download" target="_blank">this</a> website according to your host operating system,
then install Docker with default settings.
Reboot the system if necessary.
If your operating system can not meet the requirement of installing Docker,
please upgrade your operating system.
Do not install <code>Docker Toolbox</code> instead.
It seems not very stable in Windows since it is based on VirtualBox.</p>
<h2 id="preparing-dockerfile">Preparing Dockerfile</h2>
<p><code>Dockerfile</code> is the configuration file used to build a Docker image.
Now we are going to prepare a Dockerfile with proper content by using the
<a href="http://en.wikipedia.org/wiki/Text_terminal#Text_terminals" target="_blank">terminal</a> working environment.</p>
<ul>
<li>If your host is GNU/Linux or Mac, you can use the default terminal in the system.</li>
<li>If your host is Windows, open <code>PowerShell</code>.</li>
</ul>
<p>Type the following commands after the prompt, one command per line.
Every command is issued by pressing the <code>Enter</code> key.
The contents after a <code>#</code> is the comment about the command,
and you do not need to type the comment.</p>
<pre><code>mkdir mydocker # create a directory with name "mydocker"
cd mydocker # enter this directory
</code></pre><p>Now use the text editor in the host to new a file called <code>Dockerfile</code>.</p>
<ul>
<li>Windows: Type command <code>notepad Dockerfile</code> to open Notepad.</li>
<li>MacOS: Type command <code>open -e Dockerfile</code> to open TextEdit.</li>
<li>GNU/Linux: Use your favourite editor to open Dockerfile.</li>
</ul>
<p>Now copy the following contents into Dockerfile:</p>
<pre><code class="lang-dockerfile"> <span class="hljs-comment"># setting base image</span>
<span class="hljs-keyword">FROM</span> debian
<span class="hljs-keyword">RUN</span> <span class="bash">apt-get update
</span>
<span class="hljs-comment"># Set the locale</span>
<span class="hljs-keyword">RUN</span> <span class="bash">apt-get install -y locales
</span><span class="hljs-keyword">RUN</span> <span class="bash">sed -i <span class="hljs-_">-e</span> <span class="hljs-string">'s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/'</span> /etc/locale.gen
</span><span class="hljs-keyword">RUN</span> <span class="bash">dpkg-reconfigure --frontend=noninteractive locales
</span><span class="hljs-keyword">RUN</span> <span class="bash">update-locale LANG=en_US.UTF-8
</span><span class="hljs-keyword">ENV</span> LANG en_US.UTF-<span class="hljs-number">8</span>
<span class="hljs-keyword">ENV</span> LANGUAGE en_US:en
<span class="hljs-keyword">ENV</span> LC_ALL en_US.UTF-<span class="hljs-number">8</span>
<span class="hljs-comment"># new a directory for sshd to run</span>
<span class="hljs-keyword">RUN</span> <span class="bash">mkdir -p /var/run/sshd
</span> <span class="hljs-comment"># installing ssh server</span>
<span class="hljs-keyword">RUN</span> <span class="bash">apt-get install -y openssh-server
</span>
<span class="hljs-comment"># installing sudo</span>
<span class="hljs-keyword">RUN</span> <span class="bash">apt-get install -y sudo
</span>
<span class="hljs-comment"># make ssh services use IPv4 to let X11 forwarding work correctly</span>
<span class="hljs-keyword">RUN</span> <span class="bash"><span class="hljs-built_in">echo</span> AddressFamily inet >> /etc/ssh/sshd_config
</span>
<span class="hljs-comment"># defining user account imformation</span>
ARG username=ics
ARG userpasswd=ics
<span class="hljs-comment"># adding user</span>
<span class="hljs-keyword">RUN</span> <span class="bash">useradd -ms /bin/bash <span class="hljs-variable">$username</span> && (<span class="hljs-built_in">echo</span> <span class="hljs-variable">$username</span>:<span class="hljs-variable">$userpasswd</span> | chpasswd)
</span>
<span class="hljs-comment"># adding user to sudo group</span>
<span class="hljs-keyword">RUN</span> <span class="bash">adduser <span class="hljs-variable">$username</span> sudo
</span>
<span class="hljs-comment"># setting running application</span>
<span class="hljs-keyword">CMD</span> <span class="bash">/usr/sbin/sshd -D
</span></code></pre>
<p>We choose the Debian distribution as the base image,
since it can be quite small.
Change <code>username</code> and <code>userpasswd</code> above to your favourite account settings.
Save the file and exit the editor.</p>
<p>For Windows user, <code>notepad</code> will append suffix <code>.txt</code> to the saved file.
This is unexpected.
Use the following command to rename the file.</p>
<pre><code>mv Dockerfile.txt Dockerfile # rename the file to remove the suffix in Windows
</code></pre><h2 id="building-docker-image">Building Docker image</h2>
<p>Keep the Internet conntected.
Type the following command to build our image:</p>
<pre><code>docker build -t ics-image .
</code></pre><p>This command will build an image with a tag <code>ics-image</code>,
using the Dockerfile in the current directory (mydocker).
In particular, if your host is GNU/Linux,
all Docker commands should be executed with root privilege,
or alternatively you can add your account to the group <code>docker</code> before executing any docker commands.
If it is the first time you run this command,
Docker will pull the base image <code>debian</code> from <a href="https://hub.docker.com/" target="_blank">Docker Hub</a>.
This will cost several minutes to finish.</p>
<p>After the command above finished, type the following command to show Docker images:</p>
<pre><code>docker images
</code></pre><p>This command will show information about all Docker images.</p>
<pre><code>REPOSITORY TAG IMAGE ID CREATED SIZE
ics-image latest 7d9495d03763 4 minutes ago 210 MB
debian latest fb434121fc77 4 hours ago 100 MB
</code></pre><p>If you see a repository with name <code>ics-image</code>, you are done with building image.</p>
<p>Now we can remove the directory mentioned above.</p>
<pre><code>cd .. # go back to the parent directory
rm -r mydocker # remove the `mydocker` directory
</code></pre><h2 id="creating-debian-container">Creating Debian container</h2>
<p>After building the image, now we can create a container.
Type the following command:</p>
<pre><code>docker create --name=ics-vm -p 20022:22 --tmpfs /dev/shm:exec --privileged=true ics-image
</code></pre><p>This command will create a container with the following property:</p>
<ul>
<li>the name of the container is <code>ics-vm</code></li>
<li>the Docker image is <code>ics-image</code>, which we just built</li>
<li>the default SSH port (<code>22</code>) in the container is bound to port <code>20022</code> in the docker host</li>
<li>the container will get extended privileges (for GDB to run)</li>
<li>mount <code>/dev/shm</code> with an executable flag</li>
</ul>
<p>If the above command fails because a container with the same name already exists,
type the following command to remove the existing container:</p>
<pre><code>docker rm ics-vm
</code></pre><p>Then create the container again.</p>
<p>To see whether the container is created successfully,
type the following command to show containers:</p>
<pre><code>docker ps -a
</code></pre><p>This command will show information about all Docker containers.
If you see a container with name <code>ics-vm</code>, you are done with creating container.</p>
<footer class="page-footer-ex"> <span class="page-footer-ex-copyright"> By <a href="https://sashimi-yzh.github.io/" target="_blank">Zihao Yu</a>, 采用<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/cn/" target="_blank">知识共享 署名-非商业性使用-相同方式共享 3.0 中国大陆 许可协议</a>发布 </span>            <span class="page-footer-ex-footer-update"> 此页面修订于: 2021-04-19 09:48:46 </span> </footer>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="PA0.html" class="navigation navigation-prev " aria-label="Previous page: PA0 - 世界诞生的前夜: 开发环境配置">
<i class="fa fa-angle-left"></i>
</a>
<a href="0.2.html" class="navigation navigation-next " aria-label="Next page: First Exploration with GNU/Linux">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>