目录
Ubuntu安装docker
重启docker
拉取镜像
进入docker安装软件
提交docker
添加用户到docker组
进入docker
添加build用户
停止容器
保存docker镜像
load镜像
删除容器
sudo apt install docker.io
国内可用的源
Welcome to nginx! (tencentyun.com)https://ccr.ccs.tencentyun.com/
换源
在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件):
{
"registry-mirrors": ["https://ccr.ccs.tencentyun.com/"]
}
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
sudo docker pull ubunut:16.04
sudo docker run -it --name build3308 ubuntu:16.04 /bin/bash
安装完后exit退出docker
docker commit -m "Added some-package" -a "build" build3308 build:3308
docker image显示如下
build@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
build 3308 4d13656ff6cf 4 minutes ago 687MB
ubuntu 16.04 b6f507652425 3 years ago 135MB
sudo usermod -aG docker $USER
运行脚本启动容器
USER_ID=$(id -u)
GRP=$(id -g -n)
GRP_ID=$(id -g)
LOCAL_HOST=`hostname`
DOCKER_HOME="/home/$USER"
if [ "$USER" == "root" ];then
DOCKER_HOME="/root"
fi
if [ ! -d "$HOME/.cache" ];then
mkdir "$HOME/.cache"
fi
IMG="build:3308"
docker run -it \
-d \
--privileged \
--name build_3308 \
-e DOCKER_USER=$USER \
-e USER=$USER \
-e DOCKER_USER_ID=$USER_ID \
-e DOCKER_GRP=$GRP \
-e DOCKER_GRP_ID=$GRP_ID \
-e TERM="xterm-256color" \
--env ROS_DOMAIN_ID=$(date +%N) \
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
-v /media:/media \
-v $HOME/.cache:${DOCKER_HOME}/.cache \
-v /etc/localtime:/etc/localtime:rw \
-v /home/build/:/home/build \
--net host \
--shm-size 512M \
-w /home/build \
$IMG \
/bin/bash
sudo docker exec -u root -it build_3308 /bin/bash
这里的1000和build要和你宿主机上的用户名uid一致,方便后面编译出来的权限等问题
useradd -u 1000 build
查看用户信息
cat /etc/passwd
然后exit退出
sudo docker stop build_3308
提交修改
sudo docker commit build_3308 build:3308bs
修改脚本
USER_ID=$(id -u)
GRP=$(id -g -n)
GRP_ID=$(id -g)
LOCAL_HOST=`hostname`
DOCKER_HOME="/home/$USER"
if [ "$USER" == "root" ];then
DOCKER_HOME="/root"
fi
if [ ! -d "$HOME/.cache" ];then
mkdir "$HOME/.cache"
fi
IMG="build:3308bs"
docker run -it \
-d \
--privileged \
--name build_3308bs \
-e DOCKER_USER=$USER \
-e USER=$USER \
-e DOCKER_USER_ID=$USER_ID \
-e DOCKER_GRP=$GRP \
-e DOCKER_GRP_ID=$GRP_ID \
-e TERM="xterm-256color" \
--env ROS_DOMAIN_ID=$(date +%N) \
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
-v /media:/media \
-v $HOME/.cache:${DOCKER_HOME}/.cache \
-v /etc/localtime:/etc/localtime:rw \
-v /home/build/:/home/build \
--net host \
--shm-size 512M \
-w /home/build \
$IMG \
/bin/bash
重新启动docker
sudo ./start_docker.sh
进入docker
docker exec -u build -it build_3308bs /bin/bash
先docker images看下IMAGE ID
build@ubuntu:~/work$ sudo docker images
[sudo] password for build:
REPOSITORY TAG IMAGE ID CREATED SIZE
build 3308bs_1604 d40881c1ff67 29 minutes ago 706MB
build 3308bs 3cbe2a080c3a 18 hours ago 687MB
fed93a8b490d 20 hours ago 687MB
build 3308 4d13656ff6cf 22 hours ago 687MB
ubuntu 16.04 b6f507652425 3 years ago 135MB
build@ubuntu:~/work$
然后save
sudo docker save -o rk3308.tar build:3308bs_1604
docker load -i rk3308.tar
sudo docker images ps -a列出来全部
sudo docker stop (id)
sudo docker rm (id)
然后sudo docker rmi (id)