解决Docker以默认root用户运行生成的文件权限为root的问题:
以指定用户启动和进入docker容器
第一次用run创建并启动容器,运行命令:
docker run -it -u user_name --name container_name -d image_name /bin/bash
如果报错:
docker: Error response from daemon: linux spec user: unable to find user xxxx: no matching entries in passwd file.
不能使用用户名,要使用uid
docker run --user $(id -u) nginx
查看用uid:
[root@localhost ~]# id admin
指定用户uid 启动容器:
docker run -it --name pythonAdmin -u 1000 -v /home/admin/homeTVVT:/home python:3.7.1 bash
之后可以用exec进入容器,运行命令`
docker exec -it -u user_name container_name /bin/bash`
exec进入容器,运行命令:
docker exec -it -u 1000 pythonAdmin python3 /home/test1.py