在root用户下安装DOCKER
首先,更新现有的软件包列表:
$ sudo apt update
接下来,安装一些必备软件包,让 apt 通过 HTTPS 使用软件包。
sudo apt install apt-transport-https ca-certificates curl software-properties-common
然后将官方 Docker 版本库的 GPG 密钥添加到系统中
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
执行后显示
OK
将 Docker 版本库添加到APT源:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
执行后显示:
Get:1 https://download.docker.com/linux/ubuntu focal InRelease [36.2 kB]
Hit:2 http://cn.archive.ubuntu.com/ubuntu focal InRelease
Get:3 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [3056 B]
Hit:4 http://cn.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:5 http://cn.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:6 http://cn.archive.ubuntu.com/ubuntu focal-security InRelease
Fetched 39.2 kB in 2s (16.1 kB/s)
Reading package lists... Done
接下来,我们用新添加的 Docker 软件包来进行升级更新。
sudo apt update
确保要从 Docker 版本库,而不是默认的 Ubuntu 版本库进行安装:
apt-cache policy docker-ce
执行后会看到这样的结果( Docker 的版本号可能略有不同)
docker-ce:
Installed: (none)
Candidate: 5:19.03.12~3-0~ubuntu-focal
Version table:
5:19.03.12~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:19.03.11~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:19.03.10~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:19.03.9~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
请注意,到目前这一步docker-ce还未安装,但根据上一步中的列表,可以看到 docker-ce 来自 Docker 官方版本库。
最后,安装 Docker :
sudo apt install docker-ce
现在 Docker 已经安装完毕。我们启动守护程序。检查 Docker 是否正在运行:
sudo systemctl status docker
执行结果类似以下内容,说明该服务处于活动状态并且正在运行:
docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2020-07-08 02:55:20 UTC; 5min ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 4287 (dockerd)
Tasks: 8
Memory: 36.4M
CGroup: /system.slice/docker.service
└─4287 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
添加用户组
去要加入用户组的用户账号下
# 添加docker用户组,一般已存在,不需要执行
sudo groupadd docker
# 将登陆用户加入到docker用户组中
sudo gpasswd -a $USER docker
# 更新用户组
newgrp docker
# 测试docker命令是否可以使用sudo正常使用
docker version
#增加权限
sudo chmod a+rw /var/run/docker.sock
下载镜像
docker pull mesonepigreco/python-sscha
建立容器
docker run -it -v $PWD:/root mesonepigreco/python-sscha
退出容器
exit
查容器id
docker ps -a
后台重启容器
docker start 容器ID
root用户更改容器时区
docker cp /usr/share/zoneinfo/Asia/Shanghai 容器id:.
测试能否正常给容器传文件
docker cp 文件夹 容器id:目标文件夹
安装SCTK/QE/其他第一性原理软件
重新进容器端口
docker attach 容器id
在容器中安装SCTK
git clone git://git.osdn.net/gitroot/sctk/sctk.git
./configure
make sctk
把可执行文件的目录放进容器的环境变量
export PATH=$PATH:~/sctk/bin/
简单使用
复制文件夹给容器
docker cp 文件夹 容器id:目标文件夹
重新进容器端口
docker attach 容器id
建一个input.py
python3 input.py
可直接执行