ICS2017 Programming Assignment
  • Introduction
  • PA0 - 世界诞生的前夜: 开发环境配置
    • Installing a GNU/Linux VM
    • First Exploration with GNU/Linux
    • Installing Tools
    • Configuring vim
    • More Exploration
    • Transferring Files between host and container
    • Acquiring Source Code for PAs
  • PA1 - 开天辟地的篇章: 最简单的计算机
    • 在开始愉快的PA之旅之前
    • 开天辟地的篇章
    • RTFSC
    • 基础设施
    • 表达式求值
    • 监视点
    • i386手册
  • PA2 - 简单复杂的机器: 冯诺依曼计算机系统
    • 不停计算的机器
    • RTFSC(2)
    • 程序, 运行时环境与AM
    • 基础设施(2)
    • 输入输出
  • PA3 - 穿越时空的旅程: 异常控制流
    • 更方便的运行时环境
    • 等级森严的制度
    • 穿越时空的旅程
    • 文件系统
    • 一切皆文件
  • PA4 - 虚实交错的魔法: 分时多任务
    • 虚实交错的魔法
    • 超越容量的界限
    • 分时多任务
    • 来自外部的声音
    • 编写不朽的传奇
  • PA5 - 从一到无穷大: 程序与性能
    • 浮点数的支持
    • 通往高速的次元
    • 天下武功唯快不破
  • 杂项
    • 为什么要学习计算机系统基础
    • 实验提交要求
    • Linux入门教程
    • man入门教程
    • git入门教程
    • i386手册指令集阅读指南
    • i386手册勘误
    • 指令执行例子
Powered by GitBook
On this page
  • Installing Docker
  • Preparing Dockerfile
  • Building Docker image
  • Creating Debian container

Was this helpful?

  1. PA0 - 世界诞生的前夜: 开发环境配置

Installing a GNU/Linux VM

PreviousPA0 - 世界诞生的前夜: 开发环境配置NextFirst Exploration with GNU/Linux

Last updated 6 years ago

Was this helpful?

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. 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. Go back to read this lecture note carefully. Remember, the machine is always right!

Installing Docker

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.

If you already have one copy of GNU/Linux distribution different from that 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 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.

It it 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 distribution in the virtual machine. Also, please search the Internet for trouble-shooting if you have any problems about virtual machines.

Download Docker from 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 Docker Toolbox instead. It seems not very stable in Windows since it is based on VirtualBox.

Preparing Dockerfile

Dockerfile is the configuration file used to build a Docker image. Now we are going to prepare a Dockerfile with proper contentby using the working environment.

  • If your host is GNU/Linux or Mac, you can use the default terminal in the system.

  • If your host is Windows, open PowerShell.

Type the following commands after the prompt, one command per line. Every command is issued by pressing the Enter key. The contents after a # is the comment about the command, and you do not need to type the comment.

mkdir mydocker     # create a directory with name "mydocker"
cd mydocker        # enter this directory

Now use the text editor in the host to new a file called Dockerfile.

  • Windows: Type command notepad Dockerfile to open Notepad.

  • MacOS: Type command open -e Dockerfile to open TextEdit.

  • GNU/Linux: Use your favourite editor to open Dockerfile.

Now copy the following contents into Dockerfile:

 # setting base image
FROM debian

 # new a directory for sshd to run
RUN mkdir -p /var/run/sshd

 # installing ssh server
RUN apt-get update
RUN apt-get install -y openssh-server

 # installing sudo
RUN apt-get install -y sudo

 # make ssh services use IPv4 to let X11 forwarding work correctly
RUN echo AddressFamily inet >> /etc/ssh/sshd_config

 # defining user account imformation
ARG username=ics
ARG userpasswd=ics

 # adding user
RUN useradd -ms /bin/bash $username && (echo $username:$userpasswd | chpasswd)

 # adding user to sudo group
RUN adduser $username sudo

 # setting running application
CMD /usr/sbin/sshd -D

For Windows user, notepad will append suffix .txt to the saved file. This is unexpected. Use the following command to rename the file.

mv Dockerfile.txt Dockerfile     # rename the file to remove the suffix in Windows

Building Docker image

Keep the Internet conntected. Type the following command to build our image:

docker build -t ics-image .

After the command above finished, type the following command to show Docker images:

docker images

This command will show information about all Docker images.

REPOSITORY           TAG          IMAGE ID          CREATED             SIZE
ics-image            latest       7d9495d03763      4 minutes ago       210 MB
debian               latest       fb434121fc77      4 hours ago         100 MB

If you see a repository with name ics-image, you are done with building image.

Now we can remove the directory mentioned above.

cd ..           # go back to the parent directory
rm -r mydocker  # remove the `mydocker` directory

Creating Debian container

After building the image, now we can create a container. Type the following command:

docker create --name=ics-vm -p 20022:22 ics-image

This command will create a container with the following property:

  • the name of the container is ics-vm

  • the Docker image is ics-image, which we just built

  • the default SSH port (22) in the container is bound to port 20022 in the docker host

If the above command fails because a container with the same name already exists, type the following command to remove the existing container:

docker rm ics-vm

Then create the container again.

To see whether the container is created successfully, type the following command to show containers:

docker ps -a

This command will show information about all Docker containers. If you see a container with name ics-vm, you are done with creating container.

We choose the distribution as the base image, since it can be quite small. Change username and userpasswd above to your favourite account settings. Save the file and exit the editor.

This command will build an image with a tag ics-image, 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 docker before executing any docker commands. If it is the first time you run this command, Docker will pull the base image debian from . This will cost several minutes to finish.

Docker
Docker online Document
Debian 9
this
terminal
Debian
Docker Hub