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!

If you already have one copy of GNU/Linux, and you want to use your copy as the development environment, just use it! But if you encounter some troubles because of different GNU/Linux distribution or different version of the same distribution, please search the Internet for trouble-shooting.

Installing Docker

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.

Download Docker-Toolbox from this website according to your host operating system, then install Docker with default settings. Note that if your host is GNU/Linux, you can install Docker by

apt-get install docker-engine

in Ubuntu or Debian. Different distribution uses different package tools. Please search the Internet for more information. Refer to Docker online Document for more information about installing Docker on GNU/Linux.

Preparing Dockerfile

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

  • If your host is GNU/Linux, you can use the default terminal in the system.
  • If your host is Windows or Mac, open Docker Quickstart Terminal. You can find it on the desktop or in the Start Menu. If it is opened for the first time, it will perform a series of operations for initialization. After the initialization, the terminal will output a success message like
    docker is configured to use the defualt machine with IP
    Remember this IP address, since you will use it later. At the end, you will see the following prompt:
    $ _

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
touch Dockerfile   # create an empty file with name "Dockerfile", make sure the "D" is capital

Now use the text editor in the host to open 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 32bit/debian

 # setting source list
RUN echo "deb jessie main non-free contrib" > /etc/apt/sources.list

 # installing tool `gosu`
RUN set -x \
    && apt-get update && apt-get install -y --no-install-recommends ca-certificates wget \
    && wget -O /usr/local/bin/gosu "$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
    && wget -O /usr/local/bin/gosu.asc "$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
    && export GNUPGHOME="$(mktemp -d)" \
    && gpg --keyserver --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
    && gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
    && rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
    && chmod +sx /usr/local/bin/gosu \
    && gosu nobody true

 # installing ssh server
RUN apt-get install -y openssh-server
 # defining a variable
ARG username=ics
ARG userpasswd=ics

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

 # setting login user
USER $username
WORKDIR /home/$username

 # setting `sudo` as an alias of `gosu`
RUN echo "alias sudo='gosu root'" >> ~/.bashrc

 # add search path to use `dpkg`
RUN echo "export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin" >> ~/.bashrc

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

We choose the Debian distribution as the base image, since it can be quite small. Using 32bit system is to keep consistency with the textbook. Save the file and exit the editor.

Building Docker image

Go back to the Docker Quickstart Terminal and keep the Internet conntected. Type the following command to build our image:

# replace `jack` and `123456` with a username and password you prefer
docker build -t ics-image --build-arg username=jack --build-arg userpasswd=123456 .

This command will build an image with a tag ics-image, using the Dockerfile in the current directory(mydocker), while overwriting the variable username in Dockerfile. The username will be use in the container. Replace jack and 123456 in the above command with a username and password you prefer. In particular, if your host is GNU/Linux, all Docker commands should be executed with root privilege. If it is the first time you run this command, Docker will pull the base image 32bit/debian from Docker Hub. This will cost several minutes to finish.

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       475.7 MB
32bit/debian         latest       fb434121fc77      4 hours ago         272 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 -it --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
  • it is allocated with a pseudo-TTY
  • it is interactive

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.

results matching ""

    No results matching ""