首先你的container得正在運行
可通過(guò)sudo docker container ls或者sudo docker ps查看容器的CONTAINER ID
最后執行命令(其中7509371edd48 為上面查到的CONTAINER ID)
sudo docker exec -ti -u root 7509371edd48 bash
補充:解決非root用戶(hù)沒(méi)有權限運行docker命令的問(wèn)題
”Got permission denied while trying to connect to the Docker daemon
socket at unix:///var/run/docker.sock: Get
http://%2Fvar%2Frun%2Fdocker.sock/v1.26/images/json: dial unix
/var/run/docker.sock: connect: permission denied“
Manage Docker as a non-root user
The docker daemon binds to a Unix socket instead of a TCP port. By
default that Unix socket is owned by the user root and other users can
only access it using sudo. The docker daemon always runs as the root
user.If you don't want to use sudo when you use the docker command, create
a Unix group called docker and add users to it. When the docker daemon
starts, it makes the ownership of the Unix socket read/writable by the
docker group.
答案顯而易見(jiàn),要不用root用戶(hù),要不創(chuàng )建一個(gè)名為docker的用戶(hù)組,并把你需要使用docker的非root用戶(hù)添加到該組中,如果還不會(huì )搞,繼續往下看。
使用sudo獲取管理員權限,運行docker命令,這個(gè)方法在通過(guò)腳本執行docker命令的時(shí)候會(huì )有很多局限性
docker守護進(jìn)程啟動(dòng)的時(shí)候,會(huì )默認賦予名為docker的用戶(hù)組讀寫(xiě)Unix socket的權限,因此只要創(chuàng )建docker用戶(hù)組,并將當前用戶(hù)加入到docker用戶(hù)組中,那么當前用戶(hù)就有權限訪(fǎng)問(wèn)Unix socket了,進(jìn)而也就可以執行docker相關(guān)命令
sudo groupadd docker #添加docker用戶(hù)組 sudo gpasswd -a $USER docker #將登陸用戶(hù)加入到docker用戶(hù)組中 newgrp docker #更新用戶(hù)組
以上為個(gè)人經(jīng)驗,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站