Docker基础命令实战

news/2024/12/21 9:17:33/

问题:Error response from daemon: Get "https://index.docker.io/v1/search?q=mysql&n=25": dial tcp 199.59.148.9:443: connect: connection refused

在pull nginx时出现的报错,可能原因是镜像源过期了,我们需要更换镜像源

vim /etc/docker/daemon.json
{"registry-mirrors": ["https://hub.atomgit.com/repos","https://docker.m.daocloud.io","https://dockerhub.timeweb.cloud"]
}

常用命令

 拉取镜像,查看镜像,删除镜像

[root@docker-test ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
bc0965b23a04: Pull complete 
650ee30bbe5e: Pull complete 
8cc1569e58f5: Pull complete 
362f35df001b: Pull complete 
13e320bf29cd: Pull complete 
7b50399908e1: Pull complete 
57b64962dd94: Pull complete 
Digest: sha256:fb197595ebe76b9c0c14ab68159fd3c08bd067ec62300583543f0ebda353b5be
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@docker-test ~]# docker ps 
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@docker-test ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    66f8bdd3810c   3 weeks ago   192MB
[root@docker-test ~]# docker run --name=mynginx -d --restart=always -p 88:80 nginx
a55f9c7b4068d50c393f72356ee3fb7ff5a61be05dd3997f1695e851dee031ef
[root@docker-test ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                               NAMES
a55f9c7b4068   nginx     "/docker-entrypoint.…"   5 seconds ago   Up 4 seconds   0.0.0.0:88->80/tcp, :::88->80/tcp   mynginx
[root@docker-test ~]# docker rm -f  mynginx
mynginx
[root@docker-test ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

 启动容器

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]【docker run  设置项   镜像名  】 镜像启动运行的命令(镜像里面默认有的,一般不会写)# -d:后台运行
# --restart=always: 开机自启
[root@docker-test ~]# docker run --name=mynginx -d --restart=always -p 88:80 nginx
0779cfa927b4489bd7aafe07cb3500f3933f80647b9e71cb8734c2c280edf32e
#任何ip访问我的88端口,都会转发到80
[root@docker-test ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                               NAMES
0779cfa927b4   nginx     "/docker-entrypoint.…"   31 seconds ago   Up 30 seconds   0.0.0.0:88->80/tcp, :::88->80/tcp   mynginx#容器的启停
[root@docker-test ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                               NAMES
0779cfa927b4   nginx     "/docker-entrypoint.…"   22 minutes ago   Up 22 minutes   0.0.0.0:88->80/tcp, :::88->80/tcp   mynginx
[root@docker-test ~]# docker stop mynginx
mynginx
[root@docker-test ~]# docker start mynginx
mynginx
[root@docker-test ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS        PORTS                               NAMES
0779cfa927b4   nginx     "/docker-entrypoint.…"   22 minutes ago   Up 1 second   0.0.0.0:88->80/tcp, :::88->80/tcp   mynginx

 IP:88测试访问:

 

修改容器内容

修改默认的index.html 页面

1、进容器内部修改

# 进入容器内部的系统,修改容器内容
docker exec -it 容器id  /bin/bash
[root@docker-test ~]# docker exec -it 0779cfa927b4 /bin/bash
root@0779cfa927b4:/# 
root@0779cfa927b4:/# 
root@0779cfa927b4:/# 
root@0779cfa927b4:/# cd /usr/share/nginx/html/root@0779cfa927b4:/usr/share/nginx/html# 
root@0779cfa927b4:/usr/share/nginx/html# ls
50x.html  index.html
root@0779cfa927b4:/usr/share/nginx/html# echo "hello" > index.html

 

2、挂载数据到外部修改

[root@docker-test ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@docker-test ~]# docker  run --name=mynginx -d --restart=always -p 88:80 -v /data/html:/usr/share/nginx/html:ro nginx
9cf3f15f63fa8004cc9ce2ce9c70a6d04790eb819c9565712b21ccc20e4622e4
[root@docker-test ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                               NAMES
9cf3f15f63fa   nginx     "/docker-entrypoint.…"   3 seconds ago   Up 2 seconds   0.0.0.0:88->80/tcp, :::88->80/tcp   mynginx
[root@docker-test ~]# cd /data/html
[root@docker-test html]# echo "11111" > index.html
[root@docker-test html]# 

提交改变

将自己修改好的镜像提交,将自己已经修改完的镜像提交之后,在遇到镜像不能使用时,可以马上恢复

[root@docker-test ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                               NAMES
0779cfa927b4   nginx     "/docker-entrypoint.…"   34 minutes ago   Up 11 minutes   0.0.0.0:88->80/tcp, :::88->80/tcp   mynginx
[root@docker-test ~]# docker commit  -a "wangyuxuan" -m "首页变化" 0779cfa927b4 nginx:v1.0
sha256:bff0b7503eb050ecd07701a87272d238efb60256c402e461ccef4200769cf720
[root@docker-test ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
nginx        v1.0      bff0b7503eb0   6 seconds ago   192MB
nginx        latest    66f8bdd3810c   3 weeks ago     192MB
[root@docker-test ~]# docker rm -f 66f8bdd3810c
Error response from daemon: No such container: 66f8bdd3810c
[root@docker-test ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                               NAMES
0779cfa927b4   nginx     "/docker-entrypoint.…"   38 minutes ago   Up 15 minutes   0.0.0.0:88->80/tcp, :::88->80/tcp   mynginx
[root@docker-test ~]# docker rm -f 0779cfa927b4
0779cfa927b4
[root@docker-test ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@docker-test ~]# docker run --name=mynginx -d --restart=always -p 88:80 nginx
da77b3ad2b9e0da16a2cdc9f5e84e52737f29fe957c76f109e8cbc4a0ecd1c6d[root@docker-test ~]# 
[root@docker-test ~]# 
[root@docker-test ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                               NAMES
da77b3ad2b9e   nginx     "/docker-entrypoint.…"   4 seconds ago   Up 2 seconds   0.0.0.0:88->80/tcp, :::88->80/tcp   mynginx
[root@docker-test ~]# docker rm -f da77b3ad2b9e
da77b3ad2b9e
[root@docker-test ~]# 
[root@docker-test ~]# 
[root@docker-test ~]# docker run -d -p 88:80 nginx:v1.0
e60b18ed68720fee6b82838f62e9cca9403295240303d3b7aa5f623d1ad3f5af
[root@docker-test ~]# 
[root@docker-test ~]# 
[root@docker-test ~]# docker ps
CONTAINER ID   IMAGE        COMMAND                  CREATED         STATUS         PORTS                               NAMES
e60b18ed6872   nginx:v1.0   "/docker-entrypoint.…"   4 seconds ago   Up 4 seconds   0.0.0.0:88->80/tcp, :::88->80/tcp   kind_franklin

 镜像保存

[root@docker-test ~]# docker save -o test1.tar nginx:v1.0
[root@docker-test ~]# ll
total 191360
-rw-------. 1 root root      1244 Dec 19 03:33 anaconda-ks.cfg
-rw-------. 1 root root 195947008 Dec 19 05:12 test1.tar
[root@docker-test ~]# docker load -i test1.tar 
Loaded image: nginx:v1.0

补充

#查看容器日志
[root@docker-test html]# docker logs 9cf3f15f63fa
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/12/19 10:22:44 [notice] 1#1: using the "epoll" event method
2024/12/19 10:22:44 [notice] 1#1: nginx/1.27.3
2024/12/19 10:22:44 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14) 
2024/12/19 10:22:44 [notice] 1#1: OS: Linux 3.10.0-1160.el7.x86_64
2024/12/19 10:22:44 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/12/19 10:22:44 [notice] 1#1: start worker processes# docker 经常修改nginx配置文件
docker run -d -p 80:80 \
-v /data/html:/usr/share/nginx/html:ro \
-v /data/conf/nginx.conf:/etc/nginx/nginx.conf \
--name mynginx-02 \
nginx#把容器指定位置的东西复制出来 
docker cp 5eff66eec7e1:/etc/nginx/nginx.conf  /data/conf/nginx.conf
#把外面的内容复制到容器里面
docker cp  /data/conf/nginx.conf  5eff66eec7e1:/etc/nginx/nginx.conf

 


http://www.ppmy.cn/news/1556886.html

相关文章

初学stm32 --- PWM输出

目录 STM32 PWM工作过程​编辑 STM32 PWM工作过程(通道1为例) PWM模式1 & PWM模式2 向上计数配置说明​编辑 STM32 定时器3输出通道引脚 自动重载的预装载寄存器 ​编辑 PWM输出相关库函数 输出比较初始化函数: 设置比较值函数&a…

web3跨链桥协议-Nomad

项目介绍 Nomad是一个乐观跨链互操作协议。通过Nomad协议,Dapp能够在不同区块链间发送数据(包括rollups),Dapp通过Nomad的合约和链下的代理对跨链数据、消息进行验证、传输。其安全通过乐观验证机制和欺诈证明制约验证者实现&…

Mac iOS、Android、Flutter、React Native开发环境配置

1.安装XCode https://apps.apple.com/cn/app/xcode/id497799835?mt12 2.安装Android Studio https://developer.android.google.cn/studio 3.安装brew 参考地址:https://www.jianshu.com/p/22122a1d4474 /bin/zsh -c "$(curl -fsSL https://gitee.com/cunk…

microk8s使用

microk8s使用 在使用microk8s时,可以设置一些别名,使用起来保持与k8s习惯一样,具体如下 sudo snap alias microk8s.kubectl kubectl sudo snap alias microk8s.ctr ctr sudo snap alias microk8s.helm helm sudo snap alias microk8s.helm3…

DFS入门

目录 概念应用场景基本模型例题 概念 这是一种用于遍历或搜索图(包括树,树是一种特殊的图)的算法。它从起始顶点开始,沿着一条路径尽可能深地探索下去,直到无法继续,然后回溯到前一步,继续探索其…

11篇--图像边缘检测

图像梯度 要学习图像边缘检测,要先了解图像梯度的概念,我们正是通过梯度值来区分边缘像素点的 处于边缘附近的像素点与周围像素点的差距很大(不然不会有边缘呈现),所以给边缘附近的的梯度之变化很快,通过…

git pull 和 git pull --rebase 区别

git pull 和 git pull --rebase 的主要区别在于如何合并远程分支的更新到当前分支。具体来说: 1. git pull 默认情况下,git pull 相当于执行 git fetch git merge。 它会将远程分支的最新提交拉取到本地,然后将这些提交通过**合并&#xff…

EyeSoothe荣登中国区“健康健美”类第32名! ✨

眼睛疲劳、视力变化、色盲检测、虚拟眼镜试戴……这些问题,EyeSoothe都能帮你解决!作为一款全能眼健康应用,EyeSoothe集成了多个强大功能,旨在帮助你更好地保护视力,缓解眼部疲劳,随时关注眼健康。&#x1…