The tutorial about how to install docker on each platform are available on https://docs.docker.com/install/
Generally, you can download the installer according to your system.
Actually WSL is preferred on Windows 10, but you can also try Docker.
- Download
https://download.docker.com/win/stable/Docker%20for%20Windows%20Installer.exe
and install it

- Run the Docker Desktop app and wait until it is up and running, and close it. You may meet an error about the Hyper-V service, and then you need to open it and restart your computer.

- Open your favorite terminal and run
docker versionto verify the installation
Old versions of docker may be supported on Windows 7 or below, but it is not recommended for you to use these systems now.
- Download
https://download.docker.com/mac/stable/Docker.dmg
and install it.

- Run the Docker Desktop app and wait until it is up and running, and close it.

- Open your favorite terminal and run
docker versionto verify the installation
You may notice that docker can be installed on Linux, and performs much better on it! The official release of docker supports CentOS, Debian, Fedora, Ubuntu and most other Linux distributions.
You can find various images of Linux Distributions on https://hub.docker.com/search?category=os&source=verified&type=image. Here is brief list of it:
- ubuntu: https://hub.docker.com/_/ubuntu (Ubuntu is a Debian-based Linux operating system based on free software.)
- alpine: https://hub.docker.com/_/alpine (A minimal Docker image based on Alpine Linux with a complete package index and only 5 MB in size!)
- centos: https://hub.docker.com/_/centos (The official build of CentOS.)
- debian: https://hub.docker.com/_/debian (Debian is a Linux distribution that's composed entirely of free and open-source software.)
- amazonlinux: https://hub.docker.com/_/amazonlinux (Amazon Linux provides a stable, secure, and high-performance execution environment for applications.)
- fedora: https://hub.docker.com/_/fedora (Official Docker builds of Fedora)
- and many others
First you should choose a Linux Distributions on your favour, the following tutorial will take ubuntu 20.04 as an example. But if you choose other docker images, the procedure will be very similar, you only need to change the image and container names.
The following commands can be ran on any OS with docker installed.
You can download the sample image which is built by the sample Dockerfile by running
docker pull makersmelx/ubuntu280
Skip Step 1 and Step 2 if you would like to use the sample Ubuntu system.
-
Create a plain text file named
Dockerfileand edit it with the example below.# =============================================================================== # # If you do not understand how docker works, please do not modify the below lines # # =============================================================================== # FROM ubuntu:20.04 RUN sed -i 's:^path-exclude=/usr/share/man:#path-exclude=/usr/share/man:' \ /etc/dpkg/dpkg.cfg.d/excludes RUN sed -i 's/archive.ubuntu.com/ftp.sjtu.edu.cn/g' /etc/apt/sources.list RUN ln -snf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && echo $CONTAINER_TIMEZONE > /etc/timezone # =============================================================================== # # If you do not understand how docker works, please do not modify the above lines # # =============================================================================== # # Add any package you like here RUN apt-get update && \ apt-get install -y \ g++\ man \ manpages-posix\ vim\ sudo\ less\ git\ make\ cmake\ zsh # The password for root is: rootpwd RUN echo "root:rootpwd" | chpasswd # Our user is called tiij RUN useradd -rm -d /home/tiij -s /usr/bin/zsh -g root -G sudo -u 1000 tiij # The password for tiij is: nobaidu RUN echo "tiij:nobaidu" | chpasswd USER tiij WORKDIR /home/tiij
which is a recipe to build an Ubuntu system image.
In this Ubuntu system, some packages are installed. Besides root user, we have a normal (non-root or non-admin) user named tiij. The password for the root user is "root_password". The password for tiij is "do_not_use_baidu".
-
Run
docker build --tag [name of your image] [path to the directory containing dockerfile]
to build the container. For example, under the directory where your Dockerfile is, run
docker build --tag ubuntu280 ./. Then the image is calledubuntu280.If you're outside China, you may delete the line
RUN sed -i 's/archive.ubuntu.com/ftp.sjtu.edu.cn/g' /etc/apt/sources.listso that your container will use official source rather than SJTU mirror. -
Run the command like
docker run -d -it --volume=[a directory on your host computer]:[a directory in the ubuntu container] --name [container name] [image for the container]
to run the container built and named it ubuntu.
--volume=[absolute path outside]:[path in the docker]so that can share the content between the devices.For example,
docker run -d -it --volume=/Users/wujiayao/develop:/home/tiij/code --name u280 makersmelx/ubuntu280.Replace the dir as your like.
-
Run the command
docker exec -it [container name] /bin/bashto enter the container by launching a
bashprocess on it.For example,
docker exec -it u280 /bin/bashWhat happens after we use --volume in Step 3? Try
ls /home/tiij/codeor the like command to explore the directory in ubuntu container that you type in the --volumes=. See what happens. -
Use Ctrl+D or
exitto exit the container, and run the commanddocker psto check the status of running containers.
-
As default, vim is installed to this docker image. Since it may be difficult for you to use, you can install nano.
su -together with the passwordrootto become a root user andapt-get install nanoto install. Also, you may install and usesudo.
When you enter the container with a shell (eg. bash), you can use the container just like it is installed on a bare machine.
If you restart your system, the docker containers will be stopped, then you can run the command docker start ubuntu to start the container before you enter it.