docker用法

首先需要去docker官网注册你的账号,记住账号名称和密码;
然后在本地执行:

docker login

登录OK。

把ubuntu下载到本地:

sudo  docker pull ubuntu
sudo docker  images

输出:

REPOSITORY                   TAG       IMAGE ID       CREATED         SIZE
hehui09125214254/myubuntu3   latest    7502f9dc5b76   2 minutes ago   199MB
hehui09125214254/myubuntu2   latest    93ae962924f0   6 minutes ago   199MB
hehui09125214254/myubuntu    latest    b2e9d5090857   2 hours ago     199MB
hehui09125214254/myubuntu    <none>    01043a42b0da   2 hours ago     199MB

运行第一个:

sudo docker  run -it     7502f9dc5b76

然后修改文件,然后commit:

sudo docker ps  -a 

输出:

CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS                       PORTS     NAMES
c03b677d524c   7502f9dc5b76   "/bin/bash"   11 seconds ago   Exited (0) 7 seconds ago               gifted_newton
c7ead4e75cd9   7502f9dc5b76   "/bin/bash"   2 minutes ago    Exited (0) 2 minutes ago               pensive_villani
5b8c12376825   01043a42b0da   "/bin/bash"   2 hours ago      Exited (130) 4 minutes ago             interesting_keldysh

我们把第一个 commit。

sudo  docker commit  c03b677d524c hehui09125214254/myubuntu3:tag1

push

sudo  docker push   hehui09125214254/myubuntu3:tag1

然后去 https://hub.docker.com/repositories 查看,已经上传了。

Configure Docker to start on boot

sudo systemctl enable docker

sudo systemctl status docker

sudo systemctl disable docker

this command changes the restart policy for an already running container named redis.

docker update --restart unless-stopped redis

And this command will ensure all currently running containers will be restarted unless stopped.

docker update --restart unless-stopped $(docker ps -q)

docker :
安装 : https://docs.docker.com/engine/install/ubuntu/

sudo apt-get install docker-ce=5:20.10.13-0ubuntu-focal docker-ce-cli=5:20.10.13-0ubuntu-focal containerd.io

查看docker容器的ip:
iptables -t nat -L -n

以下确定没有问题
https://blog.usejournal.com/how-to-enable-docker-remote-api-on-docker-host-7b73bd3278c6

https://blog.csdn.net/qq_35615618/article/details/81201646

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

sudo systemctl daemon-reload
sudo systemctl restart docker

3.修改配置后:
sudo systemctl daemon-reload
sudo service docker restart

5.测试:
sudo docker run hello-world

6.编译镜像:
mvn clean package docker:build -DskipTests

7.docker 卸载重装
https://www.cnblogs.com/walker-lin/p/11214127.html

8:成功案例:==========================================
https://www.jianshu.com/p/dfc0ed56ebb1
》mvn clean package docker:build -Dmaven.test.skip=true

》docker run -d --name test -p 47.111.155.40:9000:9000 demo 指定IP
》docker run -d --name 容器名字 -p 9000:9000 镜像名字 // 不指定IP(=======采用这个。。。。。+ eureka )

docker run -d --net=host --privileged=true --name test -p 9000:9000 demo // 采用本机的IP(====== ok =========)

docker run -itd --name hadoop0 --hostname hadoop0 --net network_my --ip 192.168.10.30 --add-host hadoop1:192.168.10.31 --add-host hadoop2:192.168.10.32 -d -P -p 50070:50070 -p 8088:8088 hadoop:master

docker run -itd --name hadoop20 --hostname 47.111.155.40 --ip 47.111.155.40 --add-host 47.111.155.40:47.111.155.40 -d -P -p 9000:9000 demo
-p(小写)则可以指定要映射的IP和端口,但是在一个指定端口上只可以绑定一个容器

docker run --add-host=myhostname:47.111.155.40 --name test -it debian

9:同一个镜像,可以同时在多个容器中运行,

10:容器删除:
1)首先需要停止所有的容器
docker stop $(docker ps -a -q)

2)删除所有的容器(只删除单个时把后面的变量改为image id即可)
docker rm $(docker ps -a -q)

3.Is the docker daemon running?

service docker start

  1. docker create --name dataContainer -v /face ubuntu 创建一个数据卷容器

// 运行一个容器时,关联一个数据卷容器
docker run -itd --name ssh_server_test --volumes-from data1 -p 8991:22 7698f282e524

你可能感兴趣的:(命令行工具,docker,容器,运维)