docker使用笔记

查看本机上所有镜像

bash 复制代码
docker images

打包项目(打包完成后自动载入镜像)

The command docker build -t search-server . you provided is a standard way to build a Docker image. The -t flag tags the resulting image, and search-server is the tag (name) you're assigning to the image. The . at the end of the command tells Docker to use the current directory for the build context, which should contain your Dockerfile.

Here are some points to ensure and improve the build process:

  1. Dockerfile Quality: Make sure your Dockerfile is properly written, following best practices such as minimizing the number of layers, ordering multi-line arguments, and removing unnecessary files.

  2. Build Context: Only include necessary files in your build context directory to avoid sending a large context to the Docker daemon. You can use a .dockerignore file to exclude files and directories.

  3. Build Cache: Docker uses a build cache to speed up image creation. If you need to avoid using the cache, use the --no-cache flag.

  4. Multi-Stage Builds: If you have a complex build process, consider using multi-stage builds to keep your final image size small.

  5. Security: Remove any sensitive data from the Dockerfile and avoid using plain text credentials. Use secrets or environment variables where necessary.

  6. Image Size: Use slim or alpine versions of base images where possible to keep your image size small.

  7. Error Handling: Ensure that you have proper error handling and verification steps in your Dockerfile commands.

If the image builds successfully without errors and works as expected, then your build command and Dockerfile are likely fine. However, if you are encountering issues or need specific improvements, you may need to adjust your Dockerfile or build command accordingly.

bash 复制代码
docker build -t search-server .

导出docker的时候如何加TAG

增加TAG(这一步好像不需要)

bash 复制代码
docker tag 363fcdaf92c3 search-server:latest

导出镜像

bash 复制代码
docker save image-id > search-server.tar

bash 复制代码
docker save search-server:latest > search-server.tar

载入镜像

bash 复制代码
docker load < search-server.tar

运行镜像

bash 复制代码
docker run -p 4100:4100 search-server

卸载镜像

bash 复制代码
docker rm c75f653c4b23

删除镜像

bash 复制代码
docker rmi 363fcdaf92c3
相关推荐
Dontla1 小时前
Docker run --add-host参数解析(在容器启动时向/etc/hosts文件中添加自定义的主机名与IP映射)(适用于临时调试或测试)
tcp/ip·docker·容器
西西小飞龙1 小时前
Docker和K8S中pod、services、container的介绍和关系
docker·容器·kubernetes
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
kngines1 小时前
【实战 ES】实战 Elasticsearch:快速上手与深度实践-1.3.1单节点安装(Docker与手动部署)
大数据·elasticsearch·docker
飞火流星0202712 小时前
docker安装etcd:docker离线安装etcd、docker在线安装etcd、etcd镜像下载、etcd配置详解、etcd常用命令、安装常见问题总结
docker·容器·etcd
magrich14 小时前
Docker usage on ubuntu
ubuntu·docker·容器
ZZDICT18 小时前
两台互通的服务器使用Docker部署一主两从MySQL8.0.35
运维·服务器·mysql·docker
程序员没睡醒19 小时前
【小白友好】Docker 入门详解:从零开始学“应用集装箱”
docker·容器·eureka
人才瘾大19 小时前
docker和k8s
docker·kubernetes