docker operation

Docker 操作记录

docker  pull ubuntu  #use the latest tag
docker pull ubuntu:24.04  #use the 24.04 tag
docker run --rm -ti ubuntu:24.04 /bin/bash  #--rm means when we exit,the container been deleted.

查看所有container

docker ps -a
docker image ls [-a] #查看所有image
docker run --rm --network host  -ti ubuntu:24.04 /bin/bash   #host network
in docker:
apt-get update
apt-get install net-tools #ifconfig
apt-get install iputils-ping #ping
apt-get install openssl-server #ssh server
docker ps -l   #see running container
docker commit 4c301220b024  myimage:v1.0  #4c3… is container id
then we can use:
docker run –rm –network host -ti myimage:v1.0  /bin/bash
docker history myimage:v1.0 查看历史
docker image save myimage:v1.0  -o myubuntu.tar
docker load -I myubuntu.tar
docker run  --name mycontainer  --network host  -ti mydockerimage:v1.1 /bin/bash
after in docker exit:
docker ps -a: This container is just stopped.
docker start mycontainer
docker exec -ti mycontainer /bin/bash   #exec is not stop the container after exit from docker.
docker attach mycontainer  #is same with exec but after exit, container will stopped.

docker run -d  -it --name mycontainer --network host --mount type=bind,source=/ssd1/mydir,target=/mnt  mydockerimage:v1.1

resolve user is not match issue.
In host we use userid is 1007 and gid is 1009.
So in docker add group and user with 1009 and 1007

groupadd -g 1009 test0  #add a group test0 id 1009
useradd -u 1007 -g test0 test0   #add a user test0 uid is 1007 group is 1009
usermod test0 -s /bin/bash   #modify test0 default shell to /bin/bash

add tap interface operation and network operation:

docker run -d  -it --name mycontainer --network host --mount type=bind,source=/ssd1/mytest,target=/mnt  --cap-add=NET_ADMIN --cap-add=MKNOD --cap-add=SYS_ADMIN  --device /dev/net/tun:/dev/net/tun  mydockerimage:v1.3
docker start mycontainer
docker exec -ti mycontainer /bin/bash
in docker:
/etc/init.d/ssh status
/etc/init.d/ssh start #enable ssh we can ssh the docker directly.
posted on 2024-07-30 09:31  石头上长出青苔  阅读(6)  评论(0)    收藏  举报